open-telemetry / open-telemetry/opentelemetry-python
When the random seed is set, it causes duplicate traceId and spanId.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 19
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the RandomIdGenerator used in the reproduction and inspect how it creates trace IDs and span IDs after random.seed(10). Run the supplied Python example across repeated application restarts, then locate or add focused tests for this behavior. Done means seeded applications no longer produce duplicate IDs across restarts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100