Skip to content

Propagate W3C trace context for unsampled traces in event metadata - #401

Draft
w1am wants to merge 2 commits into
trunkfrom
w1am/dev-1890-clients-propagate-trace-context-for-unsampled-traces-via-w3c
Draft

Propagate W3C trace context for unsampled traces in event metadata#401
w1am wants to merge 2 commits into
trunkfrom
w1am/dev-1890-clients-propagate-trace-context-for-unsampled-traces-via-w3c

Conversation

@w1am

@w1am w1am commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Previously, the Java client only wrote tracing metadata ($traceId/$spanId) to appended events when the current trace was sampled. With head-based sampling in production, most events carried no trace context at all. Consumers reading them later couldn't link their spans back to the operation that produced the event, and events written this way can't be fixed retroactively.

Events now carry the standard W3C Trace Context in their metadata. The client writes $traceParent in the W3C format 00-{traceId}-{spanId}-{flags} whenever a trace is active, sampled or not, so consumers can always link back to the producer and see its real sampling decision. When the trace carries vendor state, such as a Datadog sampling decision, the client also writes $traceState.

On read, the client prefers $traceParent and honors its actual flags. Events written by older clients only have $traceId/$spanId, and the client falls back to those, so existing data keeps working.

For a sampled trace, the client keeps writing the legacy fields so consumers on older client versions keep working:

{
  "$traceParent": "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01",
  "$traceState": "dd=s:1",
  "$traceId": "0af7651916cd43dd8448eb211c80319c",
  "$spanId": "b7ad6b7169203331"
}

For an unsampled trace, which previously got nothing, the client writes only the new field:

{
  "$traceParent": "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-00"
}

Upgrading

Consumers using the default ParentBased sampler now respect the producer's sampling decision, so events from unsampled traces no longer produce sampled consumer spans. This is the correct W3C behavior, but you might see fewer consumer spans if your producers sample aggressively.

If you registered an OpenTelemetry SDK with an alwaysOff sampler, event metadata is now stamped with $traceParent, where previously nothing was written.

Ref: DEV-1890

@linear-code

linear-code Bot commented Aug 27, 2026

Copy link
Copy Markdown

DEV-1890

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.

1 participant