open-telemetry / open-telemetry/opentelemetry-python

When the random seed is set, it causes duplicate traceId and spanId.

Open
#4,376 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.