TracingEventReceiver: Explicit parent for unconnected spans#83
Open
rawler wants to merge 2 commits into
Open
Conversation
TracingEventSender, being a tracing Subscriber, did not track which spans were entered per thread. When spans or events used implicit (contextual) parent lookup, the serialized events carried no parent ID, making it impossible for the receiver to reconstruct correct parent-child relationships — especially when multiple threads emit concurrently. TracingEventSender now maintains a per-thread span stack (via thread_local) and falls back to it when an event or span has no explicit parent, ensuring serialized events always carry accurate parent IDs.
BREAKING: TracingEventReceiver::new() now takes an additional `root_span: Option<Id>` parameter. Previously, spans and events arriving without a parent were replayed using contextual parent lookup (Attributes::new), non-deterministically attaching to whatever span happened to be current on the receiver thread. This made receiver output dependent on ambient subscriber state. TracingEventReceiver now accepts an explicit root_span. Parentless spans and events are attached to it via Attributes::child_of. When no root_span is provided, they are created as explicit roots (Attributes::new_root), removing the dependency on receiver-side span context entirely.
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.
Summary
BREAKING:
TracingEventReceiver::new()now takes an additionalroot_span: Option<Id>parameter.Previously, spans and events arriving without a parent were replayed using contextual parent lookup (
Attributes::new), non-deterministically attaching to whatever span happened to be current on the receiver thread. This made receiver output dependent on ambient subscriber state.root_spaninTracingEventReceiver::new()root_spanviaAttributes::child_ofroot_spanis provided, create explicit roots (Attributes::new_root) instead of using contextual lookupDepends on #75.