Skip to content

feat: distributed tracing — nest Claude Code under an inbound TRACEPARENT#7

Draft
XinweiHe wants to merge 1 commit into
mainfrom
feat/distributed-tracing-traceparent
Draft

feat: distributed tracing — nest Claude Code under an inbound TRACEPARENT#7
XinweiHe wants to merge 1 commit into
mainfrom
feat/distributed-tracing-traceparent

Conversation

@XinweiHe

Copy link
Copy Markdown
Contributor

Draft for review. Adds W3C trace-context propagation so a backend that launches Claude Code (e.g. backend → sandbox → Claude Code) gets one connected trace, with the Claude Code session nested under the backend span.

How

  • Reads TRACEPARENT (and BAGGAGE) from the hook process's environment and parents the ask-root spans under it (same trace_id).
  • Standard OTEL propagation — TRACEPARENT env carrier is OTEP-0258; the backend builds it from get_current_trace_id()/get_current_span_id().
  • Fail-open: no/malformed TRACEPARENT → fresh root trace, exactly as today.
  • Baggage entries → traceroot.baggage.* attributes for correlation.
  • Per-process scope: each claude invocation reads its own env, so reused/parallel-flow sandboxes stay separate (never a global).

Verified

  • 87 unit tests (+4: nest-under-traceparent, fresh-trace-without, malformed-fail-open, baggage→attrs).
  • End-to-end against prod: backend agent_task span → Claude Code Turn → LLM → tools, all one trace.

Notes for merge

  • Behavioral change: now honors any TRACEPARENT in env (standard, but worth a glance).
  • Recommend a version bump (feature) so installs detect the update, e.g. 0.1.0 → 0.2.0.
  • Example backend (backend → sandbox → Claude Code) lives in the platform repo's examples/claude-code-distributed-tracing/.

🤖 Generated with Claude Code

…RENT

Read W3C trace context from the environment (TRACEPARENT, and BAGGAGE) and parent
the ask-root spans under it, so a backend that launches Claude Code (e.g.
backend -> sandbox -> claude) gets ONE connected trace with the Claude Code
session nested under the backend span. Standard OTEL propagation (OTEP-0258
env carriers). Fail-open: no/malformed TRACEPARENT -> fresh root trace, exactly
as before. Baggage entries are stamped as traceroot.baggage.* attributes.

Scoped per-process (each claude invocation reads its own env), so reused or
parallel-flow sandboxes stay correctly separated. +4 tests (87 total).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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