Propagate W3C trace context for unsampled traces in event metadata - #401
Draft
w1am wants to merge 2 commits into
Draft
Propagate W3C trace context for unsampled traces in event metadata#401w1am wants to merge 2 commits into
w1am wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
$traceParentin the W3C format00-{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
$traceParentand 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
ParentBasedsampler 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
alwaysOffsampler, event metadata is now stamped with$traceParent, where previously nothing was written.Ref: DEV-1890