[FEATURE][Trace] Support per-request trace context propagation for LLM API calls

Resolved 💬 1 comment Opened May 12, 2026 by jld2700 Closed Jun 16, 2026

Request

Claude Code can export its own OpenTelemetry telemetry via OTLP, and it can also call an Anthropic-compatible proxy through ANTHROPIC_BASE_URL.

However, when Claude Code sends LLM API requests to the configured proxy, there does not appear to be a supported way to inject the current active trace context into each outbound model request.

Please support one of the following:

  1. Automatically inject W3C trace context into outbound LLM API calls when Claude Code OTEL is enabled:
  • traceparent
  • tracestate
  • optionally baggage
  1. Or expose a supported hook/helper for outbound model requests, for example:
  • PreLLMRequest
  • ability to modify outbound request headers
  • access to the current active OTEL span/context
  1. Or support a dynamic custom header helper, similar in spirit to apiKeyHelper, but for arbitrary headers:
  • invoked per request
  • can return headers like traceparent / baggage

Use case

We run Claude Code against a local LLM proxy:

ANTHROPIC_BASE_URL=http://localhost:8317

Both Claude Code and the proxy export telemetry to the same OTLP collector.

Desired trace tree:

Claude Code span
  -> outbound LLM API request
    -> llm-proxy server span
      -> proxy/provider/model spans

Today this cannot be represented as a single distributed trace unless Claude Code sends a valid per-request traceparent header to the proxy.

Why static headers are insufficient

ANTHROPIC_CUSTOM_HEADERS can add static headers, but a fixed traceparent is not semantically correct because many unrelated requests would share the same parent span.

Hooks and MCP also do not appear to expose a PreLLMRequest / PreModelRequest event that can modify outbound LLM request headers.

Expected behavior

When OTEL is enabled, Claude Code should either:

  • propagate the active trace context on each LLM API HTTP request automatically, or
  • provide a supported extension point to add dynamic per-request headers.

Acceptance criteria

  • Each Claude Code LLM API request can include a fresh/current traceparent.
  • Downstream Anthropic-compatible proxies can extract the context and attach their spans to the Claude Code trace.
  • This works with ANTHROPIC_BASE_URL.
  • Static ANTHROPIC_CUSTOM_HEADERS remains supported, but is not the only option for trace propagation.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗