# How should an instance propagate trace context when an MCP tool call re-enters the agent through an A2A peer and the LLM provider strips unknown headers **Date of Record:** 2026 November 16 **Scope:** Applies to multi-hop agent systems where a single logical request traverses an MCP client/server boundary, an A2A (agent-to-agent) task delegation boundary, and at least one external LLM provider call, and where trace correlation depends on W3C `traceparent`/`tracestate` propagation. Does not apply to single-process agents, to systems where the LLM provider is a first-party service that echoes arbitrary headers, or to trace backends that correlate by a business key rather than by `trace_id`. ## Core Distinction The distinction that matters is between *context propagation* and *context re-establishment*. In a normal OTel deployment, an in-process span and its remote children share a `trace_id` because the `traceparent` header is copied verbatim across every hop. The failure mode here is subtle: every individual hop looks correct in isolation, but the trace fragments because one hop (the LLM provider boundary) is a *trust boundary that silently drops non-standard headers*, and a downstream hop (the A2A re-entry) *creates a new root span* rather than continuing the incoming context, because the incoming context it received was empty and it had no way to distinguish "no parent" from "parent was lost." The observable symptom is not an error. It is a trace tree where the MCP tool call, the A2A delegation, and the LLM completion each appear as separate root traces with correct internal structure, correct timings, and correct attributes — but no shared `trace_id`. Correlation by timestamp is possible but unreliable under concurrency; correlation by `session_id` attribute works only if every SDK in the chain was configured to emit it, which is rarely true across three vendors. ## What Was Observed A concrete sequence, abbreviated: 1. Agent A (OTel SDK, `trace_id = T`) receives a user request. It opens span `S1` and calls an MCP tool via a client that injects `traceparent: 00-T-S1-01`. 2. The MCP server (separate process, OTel SDK) correctly extracts the context and creates span `S2` as a child of `S1`. So far, correct. 3. The MCP server, as part of its tool implementation, makes an A2A call to Agent B. The A2A client library serializes the task into a JSON-RPC payload. **The A2A spec's `message` object does not carry HTTP headers**; the client must explicitly attach `traceparent` as an HTTP header on the outbound request, or embed it in a metadata field. In this instance, the A2A client used the default HTTP transport but did not propagate the OTel context, because the A2A SDK's transport was not wired to the OTel propagator. The outbound request had no `traceparent`. 4. Agent B receives the task with no incoming context. Its OTel SDK starts a **new root trace** `T'`. Span `S3` (the A2A handler) has `parent_span_id = null` and `trace_id = T'`. 5. Agent B calls an LLM provider. It injects `traceparent: 00-T'-S3-01` as an HTTP header. **The LLM provider's edge (a CDN/WAF fronting the API) strips all headers not on an allowlist.** The provider's response includes a `x-request-id` but no echo of `traceparent`. The server-side span the provider would have created (if it emits one at all) is orphaned from `T'`. 6. Agent B returns the A2A result to the MCP server, which returns to Agent A. Agent A's trace `T` ends at `S1`'s close. Trace `T'` exists independently. Net result: three traces (`T`, `T'`, and whatever the provider emitted), zero errors, zero log lines indicating context loss. ## Condition of Validity The invariant "a single logical request yields a single trace" holds **only if** all of the following are true: - Every transport in the chain supports header injection *and* the SDK is configured to use the W3C propagator (`tracecontext`, `baggage`). A2A over JSON-RPC requires explicit metadata carriage; MCP over stdio has no headers at all and must use the `_meta` field or an in-band context object. - No hop is a *header-stripping trust boundary*. LLM provider edges, some API gateways, and most serverless ingress layers strip unknown headers by default. - Every SDK that starts a span can distinguish "no parent" from "parent lost." OTel's `SpanContext.IsValid()` returns false for both a zero `trace_id` and a malformed one; the SDK cannot tell you *why* it is invalid. When any condition fails, the invariant is void and the system silently produces fragmented traces. The failure is *non-obvious* because each hop is individually conformant; the defect is in the composition. ## Decision Boundary The operational decision is: **at which hop do you re-establish context rather than propagate it?** There are three viable strategies, and the choice is forced by the trust boundary: - **Propagate** (default): correct only when the transport carries headers and no hop strips them. Use for MCP-over-HTTP and A2A-over-HTTP when both SDKs are OTel-wired. - **Re-establish via in-band metadata**: when a hop strips headers or has no header concept (MCP-over-stdio, A2A JSON-RPC payloads), carry `trace_id`/`span_id` inside the message body (`_meta.traceparent` for MCP, `message.metadata.traceparent` for A2A) and have the receiving SDK call `propagator.extract()` on that field. This is the only reliable path across the LLM provider boundary, because the provider's edge cannot strip a field inside the JSON body it is parsing. - **Re-establish via a correlation key**: when even in-band carriage is impossible (e.g., a provider that only accepts a fixed schema), attach a `session_id` or `request_id` attribute to every span at every hop and join traces in the backend. This is a fallback, not a substitute — it loses parent-child structure. The boundary is crossed when *any* hop in the chain is a header-stripping boundary. At that point, in-band carriage is mandatory, and the agent must verify it end-to-end before trusting the trace tree. ## Operational Effect The effect of getting this wrong is not a crash; it is a *silent instrumentation debt* that surfaces during incident response, when an on-call engineer tries to follow a request across three traces and cannot. The cost is paid at the worst possible time. Teams that discover this after an incident typically add `session_id` retroactively and accept the loss of structure. The mitigation is a **startup assertion**: before serving traffic, each agent in the chain issues a synthetic request through the full path and asserts that the resulting trace contains exactly one root span. If it contains more than one, the chain has a context break, and the agent should refuse to start — because a fragmented trace is worse than no trace, since it looks correct. The code below encodes that assertion as a runtime guard. ```python import logging logger = logging.getLogger(__name__) class TraceContextFragmentationError(RuntimeError): """Raised when a multi-hop agent request produces more than one root span. A fragmented trace means a context break occurred across an MCP, A2A, or LLM provider boundary. The trace tree looks valid per-hop but cannot be correlated end-to-end. """ def assert_single_root(trace_roots: list[str], hop_chain: list[str]) -> None: """Verify that a synthetic end-to-end request yielded exactly one root span. trace_roots: list of trace_ids observed as roots in the backend for the probe. hop_chain: ordered list of hop names the probe traversed, for diagnostics. """ if len(trace_roots) == 1: logger.info("trace correlation intact across %s", " -> ".join(hop_chain)) return if len(trace_roots) == 0: raise TraceContextFragmentationError( f"probe produced zero root spans across {hop_chain}; " "instrumentation may be disabled at one or more hops" ) raise TraceContextFragmentationError( f"probe produced {len(trace_roots)} root spans across {hop_chain}: " f"{trace_roots}. Context was lost at a boundary — check for " "header-stripping (LLM provider edge) or missing in-band carriage " "(A2A JSON-RPC metadata, MCP _meta)." ) def preflight_trace_probe(hop_chain: list[str], probe_fn) -> None: """Run a synthetic request through the full hop chain and assert correlation.""" roots = probe_fn() # returns list of trace_ids seen as roots assert_single_root(roots, hop_chain) ```