Skip to content

Preserve random trace ID flag for child spans#5241

Merged
xrmx merged 3 commits into
open-telemetry:mainfrom
HasanTasdiq:codex/fix-random-trace-id-inherited-parent
May 21, 2026
Merged

Preserve random trace ID flag for child spans#5241
xrmx merged 3 commits into
open-telemetry:mainfrom
HasanTasdiq:codex/fix-random-trace-id-inherited-parent

Conversation

@HasanTasdiq
Copy link
Copy Markdown
Contributor

@HasanTasdiq HasanTasdiq commented May 21, 2026

Fixes #5240

Summary

  • Set the W3C random-trace-id flag from the configured ID generator only when this tracer generates a new root trace ID.
  • Preserve the parent random-trace-id bit when creating child spans that continue an existing trace ID.
  • Added regression coverage for child spans from remote parent contexts with the random bit unset and set.
  • Added the towncrier changelog fragment for this trace propagation fix.

Why

The 1.42.0 random trace ID support consults the ID generator for every new span. That makes child spans advertise RANDOM_TRACE_ID even when they continue a trace ID inherited from an incoming parent that did not set the bit.

Testing

  • Ran: local issue reproduction before and after the fix; remote parent flags 0x01 changed from child flags 0x03 to child flags 0x01
  • Ran: python3 -m pytest opentelemetry-sdk/tests/trace/test_trace.py::TestSpanCreation::test_start_span_preserves_parent_random_trace_id_flag - passed
  • Ran: python3 -m pytest opentelemetry-sdk/tests/trace/test_trace.py::TestSpanCreation::test_start_span_implicit opentelemetry-sdk/tests/trace/test_trace.py::TestSpanCreation::test_start_span_explicit opentelemetry-sdk/tests/trace/test_trace.py::TestSpanCreation::test_start_span_preserves_parent_random_trace_id_flag - passed
  • Ran: python3 -m ruff check opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py opentelemetry-sdk/tests/trace/test_trace.py - passed
  • Ran: python3 -m py_compile opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py opentelemetry-sdk/tests/trace/test_trace.py - passed

Notes

  • Full python3 -m pytest opentelemetry-sdk/tests/trace/test_trace.py ran 107 passed and failed only TestTracer.test_shutdown in this shell because shutil.which("python") returned None; this environment has python3 but no python executable on PATH.
  • The full-file run also showed the separate SelectableGroups warning tracked by Importing opentelemetry.context issues a warning in Python 3.10 and 3.11 #5231.

@HasanTasdiq HasanTasdiq marked this pull request as ready for review May 21, 2026 03:26
@HasanTasdiq HasanTasdiq requested a review from a team as a code owner May 21, 2026 03:26
@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest May 21, 2026
Comment thread .changelog/5241.fixed Outdated
@xrmx xrmx added this pull request to the merge queue May 21, 2026
Merged via the queue into open-telemetry:main with commit 05ee71b May 21, 2026
479 checks passed
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest May 21, 2026
xrmx pushed a commit that referenced this pull request May 21, 2026
* fix: preserve random trace flag for child spans

Assisted-by: OpenAI Codex

* chore: add changelog for random trace flag fix

Assisted-by: OpenAI Codex

* chore: clarify random trace flag changelog

Assisted-by: OpenAI Codex

Co-authored-by: Tasdiqul Islam <tasdiq088@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

3 participants