Skip to content

feat(eventing): continue the trace a CloudEvent was published under - #117

Open
Develebook wants to merge 1 commit into
developfrom
feat/cloudevent-trace-context
Open

Develebook wants to merge 1 commit into
developfrom
feat/cloudevent-trace-context

Conversation

@Develebook

Copy link
Copy Markdown
Contributor

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.

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>

SawwR commented Oct 26, 2026

Copy link
Copy Markdown

⚠️ Version not bumped

pyproject.toml has version = "0.8.2" on this PR branch (feat/cloudevent-trace-context) and the same 0.8.2 on the target branch (develop). The PR version must be greater than the target version (semver). Please bump the version in [project].version before merging.


Generated by Claude Code

@solicho
solicho self-requested a review October 27, 2026 07:28

@solicho solicho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_valid guard), so a caller that already holds a span keeps it as the parent — covered by test_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 and test_the_delivered_events_trace_wins_over_the_envelopes.
  • Missing / empty / non-string / malformed traceparent all fall through to a self-started trace: the is_valid re-check after propagate.extract rejects 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

This branch has not been deployed

No deployments
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.

3 participants