Skip to content

Commit d369f6e

Browse files
feat(traces): span handles (#951)
* feat(traces): span handles Adds the Span interface (posthog.tracing.span, the only public module in the package) and its handles. The recording span keeps its timing on a monotonic clock, with children of a local parent on the root's clock basis so they stay inside it; end() is idempotent and hands the pipeline one record. The no-op handle is returned when tracing cannot run, and the pass-through handle echoes an inbound traceparent and tracestate so a service with tracing off still forwards the trace, including from spans nested inside it. Entering a handle makes it the active span for the block and records an exception raised out of it. Not reachable from the client. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TkZAsCciW4PV8ZdcCHmAbA * fix(traces): detach before ending and record only Exception on scoped exit A generator closed early or a cancelled task raised GeneratorExit or CancelledError through __exit__ and shipped as an error span. The scoped form now records an Exception only, still ending on every exit. The span is detached before end() so nothing started from the on_end path nests under a span that is over. end() flips its flag under the handle's lock, and a deactivate that finds no token for the context says so at debug. --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 584230f commit d369f6e

4 files changed

Lines changed: 1146 additions & 0 deletions

File tree

0 commit comments

Comments
 (0)