Description
Problem
In SdkSpanBuilder.startSpan(), when creating a root span (!parentSpanContext.isValid()) with a random IdGenerator (idGenerator.generatesRandomTraceIds() == true), parentContextForSampler replaces the Span in parentContext with RANDOM_TRACE_ID_PRIMORDIAL_SPAN, whose TraceState is TraceState.getDefault().
If a caller attaches an invalid SpanContext carrying initial TraceState (for example, ot=rv:... per Do not overwrite explicit randomness) to parentContext:
Sampler.shouldSample()cannot observeparentSpanContext.getTraceState()throughparentContextForSampler(even thoughSdkSpanBuilder.java:258passesparentSpanContext.getTraceState()tosamplingResult.getUpdatedTraceState(...)).CompositeSampler.shouldSample()readstraceStatefromparentContext(now empty) and reuses it ingetUpdatedTraceState()(line 95), losing the caller's initialTraceState.
When idGenerator.generatesRandomTraceIds() is false, parentContextForSampler is left unchanged and the caller's TraceState is preserved.
Note: Upstream spec clarification on ShouldSample root TraceFlags and root-span TraceState is also tracked in open-telemetry/opentelemetry-specification#5471 and open-telemetry/opentelemetry-specification#5472.
Metadata
Metadata
Assignees
Type
Fields
Priority
Projects
- StatusShow more project fieldsNo status
Activity
jack-berg commentedon Nov 25, 2026
So something like the following?
dashpole commentedon Dec 4, 2026
Yes, that looks right to me