-
Notifications
You must be signed in to change notification settings - Fork 661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When the random seed is set, it causes duplicate traceId and spanId. #4376
Comments
I'm not sure the current behavior is really a bug, this is what I would expect to happen. Could you explain a little more the use case for changing the behavior? |
imagine you're running some scientific computing code that involves randomness and you want to persist the seed for reproducibility. if your teammates run the instrumented code with the same seed (to check your results), they'll generate traces with the same ID - is that a good thing? minimally, I can imagine it'd be inconvenient, because each run would no longer be uniquely identifiable from a tracing perspective (you'd need to know out-of-band information like the timestamp) while I think it makes sense to be able to control the seed of the OTel random generator, I don't think it should use the global seed. |
In some scenarios, such as model performance evaluation, we prefer the split between training and testing data to be random. By setting a fixed random seed, we can ensure that each model uses the same dataset for training and validation, enabling fair comparisons. In this context, integrating OpenTelemetry can lead to the duplication of traceId and spanId if the application is restarted. Here’s a demo: import uvicorn _logger = getLogger(name) def init(): app = FastAPI() @app.get("/health") @app.get("/evaluation") if name == "main": After restarting the application (due to an update or a manual restart), accessing the /health endpoint generates the same traceId 164207228320579316746596838417247989971 and spanId 273610340023782072. However, the span name has changed to /health, which is clearly incorrect. |
Describe your environment
OS: ALL
Python version: Python 3.10.16
SDK version: 1.29.0
What happened?
After setting a random seed in the Python application, the traceId and spanId are duplicated after each restart of the application.
Steps to Reproduce
from opentelemetry.sdk.trace import RandomIdGenerator
if name == "main":
import random
random.seed(10)
id_generator = RandomIdGenerator()
trace_id = id_generator.generate_trace_id()
span_id = id_generator.generate_span_id()
# Every time the main function is run, the trace_id is always 164207228320579316746596838417247989971
print(trace_id)
# Every time the main function is run, the span_id is always 273610340023782072
print(span_id)
Expected Result
Each time the main function runs, the trace_id and span_id are different.
Actual Result
Every time the main function is run, the trace_id is always 164207228320579316746596838417247989971
Every time the main function is run, the span_id is always 273610340023782072
Additional context
No response
Would you like to implement a fix?
Yes
The text was updated successfully, but these errors were encountered: