Skip to content

fix(cloud): propagate OTEL trace context across worker→DO boundary#320

Merged
RhysSullivan merged 1 commit intomainfrom
rs/mcp-trace-propagation
Apr 18, 2026
Merged

fix(cloud): propagate OTEL trace context across worker→DO boundary#320
RhysSullivan merged 1 commit intomainfrom
rs/mcp-trace-propagation

Conversation

@RhysSullivan
Copy link
Copy Markdown
Owner

Summary

  • Axiom showed mcp.request (worker) and McpSessionDO.* (DO) in separate traces — the worker's WebSdk and the DO's WebSdk live in different isolates and nothing carried OTEL context across the stub.init() / stub.handleRequest() RPC, so the DO emitted a brand-new root trace per call.
  • Worker now builds a W3C traceparent from Effect.currentSpan and ferries it to the DO (header on handleRequest, second arg on init). DO parses it and anchors its root span via OtelTracer.withSpanContext.
  • Added a miniflare e2e regression guard: McpSessionDO.init / handleRequest must share trace_id with the corresponding mcp.request and point to it via parent_span_id.

Test plan

  • bun run vitest run --config vitest.node.config.ts (cloud): 29/29 pass, including the new propagation assertion.
  • Deploy to staging and confirm Axiom stitches mcp.request + McpSessionDO.* into a single trace.

Worker and McpSessionDO run in separate isolates with independent WebSdk
tracer providers, so nothing carried trace context across stub.init() /
stub.handleRequest() — the DO emitted a brand-new root trace per request
and mcp.request + McpSessionDO.* never stitched in Axiom.

Ferry the worker-side span's SpanContext across as a W3C traceparent:
- mcp.ts builds it from Effect.currentSpan and either injects a
  traceparent header on the forwarded Request (handleRequest) or passes
  it as a new second arg to stub.init(token, traceparent).
- mcp-session.ts parses it and uses OtelTracer.withSpanContext so the
  DO's root Effect span lands under the worker span.

Regression guard added to the miniflare e2e suite (extended CapturedSpan
to track traceId/spanId/parentSpanId) — asserts McpSessionDO.init shares
trace_id with mcp.request and has its spanId as parent_span_id, plus the
same for a follow-up tools/list → McpSessionDO.handleRequest.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 18, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
executor-marketing 867ad76 Commit Preview URL

Branch Preview URL
Apr 18 2026, 08:52 PM

@RhysSullivan RhysSullivan merged commit 9ec1ab6 into main Apr 18, 2026
8 checks passed
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