Repository navigation
feat(eventing): continue the trace a CloudEvent was published under - #117
Develebook wants to merge 1 commit into
Conversation
A producer that publishes a CloudEvent with the distributed-tracing extension (traceparent, optionally tracestate) states the trace the event belongs to, but every delivery started a trace of its own: nothing read the extension, so process_event, the handler spans and the instrumented calls a handler makes (httpx) never joined the producer's trace. _dispatch_cloud_event, the point NATS, Dapr and the sessions bus share right before process_event opens a delivery's first span, now extracts that context with the global propagator and makes it current for the dispatch, detaching it in finally. The delivered event is read before its Dapr envelope. A missing, empty, non-string or malformed traceparent changes nothing, and a caller that already has a span current keeps it as the parent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Generated by Claude Code |
solicho
left a comment
There was a problem hiding this comment.
Review — continue the producer's trace on CloudEvent delivery
Reviewed d04c219 against develop base 1f87d53. Scope: trace-context extraction in _dispatch_cloud_event, the new producer_trace_context helper, and its tests.
Correct and well-scoped:
- The W3C context is extracted only when nothing is already tracing the delivery (the
span.get_span_context().is_validguard), so a caller that already holds a span keeps it as the parent — covered bytest_a_caller_that_traces_the_delivery_keeps_its_own_span_as_parent. - The inner delivered event is preferred over its Dapr envelope (
producer_trace_context(cloud_event, delivered)after the unwrap), matching the documented precedence andtest_the_delivered_events_trace_wins_over_the_envelopes. - Missing / empty / non-string / malformed
traceparentall fall through to a self-started trace: theis_validre-check afterpropagate.extractrejects an unparseable carrier, and the parametrized test exercises each case. - The attached context is always detached in
finally, on both the success and the exception path (test_the_previous_context_is_current_again_when_processing_fails).
No blocking findings.
Automated "Version not bumped" check — not applicable, triaged. The bot flags that pyproject.toml stays at 0.8.2. That is the expected behaviour for this repo: [project].version is a base version and release versions come from the git tag (see 31375cc "release versions come from the tag" and 904ecac "version back to 0.8.2"). Feature PRs into develop record their changes in the CHANGELOG.md [Unreleased] section — which this PR does — and do not bump the version. So no bump is expected here; the check is a false positive for a routine develop PR.
CI: Lint, Type Check & Test — green.
Verdict: APPROVE.
🤖 Generated with Claude Code
A producer that publishes a CloudEvent with the distributed-tracing extension (traceparent, optionally tracestate) states the trace the event belongs to, but every delivery started a trace of its own: nothing read the extension, so process_event, the handler spans and the instrumented calls a handler makes (httpx) never joined the producer's trace.
_dispatch_cloud_event, the point NATS, Dapr and the sessions bus share right before process_event opens a delivery's first span, now extracts that context with the global propagator and makes it current for the dispatch, detaching it in finally. The delivered event is read before its Dapr envelope. A missing, empty, non-string or malformed traceparent changes nothing, and a caller that already has a span current keeps it as the parent.