Skip to content

TracingEventReceiver: Explicit parent for unconnected spans#83

Open
rawler wants to merge 2 commits into
slowli:mainfrom
rawler:receiver-root-span
Open

TracingEventReceiver: Explicit parent for unconnected spans#83
rawler wants to merge 2 commits into
slowli:mainfrom
rawler:receiver-root-span

Conversation

@rawler
Copy link
Copy Markdown

@rawler rawler commented Mar 19, 2026

Summary

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.

  • Accept an explicit root_span in TracingEventReceiver::new()
  • Parentless spans/events are attached to root_span via Attributes::child_of
  • When no root_span is provided, create explicit roots (Attributes::new_root) instead of using contextual lookup

Depends on #75.

rawler added 2 commits March 19, 2026 20:09
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.
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