Skip to content

Keep the TraceState of an invalid parent when sampling a root span - #9071

Open
Eliot5566 wants to merge 1 commit into
open-telemetry:mainfrom
Eliot5566:sampler-root-tracestate
Open

Eliot5566 wants to merge 1 commit into
open-telemetry:mainfrom
Eliot5566:sampler-root-tracestate

Conversation

@Eliot5566

Copy link
Copy Markdown

Summary

Fix an issue where SdkSpanBuilder loses the initial TraceState from an invalid parent span when using a random trace ID.

Changes

  • Preserve the original TraceState in the invalid parent span passed to the sampler.
  • Retain the random trace ID flag.
  • Reuse the existing shared instances when TraceState is empty or the parent context is root, avoiding unnecessary allocations.

Testing

  • Added a regression test verifying that the sampler receives the original TraceState and that the resulting span preserves it.
  • Verified that the parent span remains invalid and retains the random trace ID flag.
  • All CI checks passed on my fork, including cross-platform Java tests, GraalVM, and Spotless.

Fixes #9062

I used Claude to help write and test this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Hq1ACTsK85bRrY28fUQ7b3

When the IdGenerator produces random trace IDs, the span builder
replaces the parent span in the sampling context with a primordial span
that has an empty TraceState. An invalid parent that carries initial
TraceState (for example explicit randomness in ot=rv) was therefore
hidden from the sampler.

Build the sampling parent span from the parent's TraceState when it is
not empty. The singleton is still used when there is nothing to keep.

Fixes open-telemetry#9062

Claude-Session: https://claude.ai/code/session_01Hq1ACTsK85bRrY28fUQ7b3
@Eliot5566
Eliot5566 requested a review from a team as a code owner November 27, 2026 01:36
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-11-27 02:12 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with the author? Comment /dashboard route:author to route it back.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.56%. Comparing base (a92b644) to head (b19ed55).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #9071   +/-   ##
=========================================
  Coverage     90.56%   90.56%           
- Complexity    11220    11222    +2     
=========================================
  Files          1032     1032           
  Lines         30599    30608    +9     
  Branches       4010     4011    +1     
=========================================
+ Hits          27711    27721   +10     
  Misses         1913     1913           
+ Partials        975      974    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SdkSpanBuilder drops invalid parent TraceState when IdGenerator.generatesRandomTraceIds() is true

1 participant