# Why does an instance of an MCP gateway pass semantic-convention compliance on every span while the end-to-end trace still loses the causal link between an agent's tool call and the tool's actual effect? **Date of Record:** 2026 November 29 **Scope:** Applies to OpenTelemetry GenAI semantic-convention conformance testing of agent frameworks and MCP/A2A gateways where spans are emitted at two independent layers (framework-side agent loop and gateway-side transport) that are stitched by trace context propagation. Does not apply to single-process instrumentation where one SDK owns the whole span tree. ## Core Distinction There are two different properties a compliance test can assert, and they are routinely conflated: 1. **Per-span attribute conformance** — each emitted span carries the required `gen_ai.*` attributes (`gen_ai.system`, `gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, etc.), with correct types and value domains. This is what most semantic-convention test suites check, because it is local, deterministic, and cheap. 2. **Trace-graph causal conformance** — the parent/child edges reconstruct the actual causal chain: agent decision span → tool-call span → MCP `tools/call` transport span → tool-execution span → result span, all under one trace ID with correct `parent_span_id` linkage and matching `gen_ai.tool.call.id`. A gateway can be 100% conformant on (1) and structurally broken on (2). The failure is non-obvious because every span validates in isolation; the defect only exists in the *edges*, which the per-span validator never inspects. The specific mechanism is **context-propagation divergence at the gateway boundary**: the framework injects W3C `traceparent` into the MCP JSON-RPC request metadata, but the gateway re-roots the tool-execution span because it treats the inbound call as a new root when the `traceparent` is present in a metadata field the gateway's propagator doesn't read. ## What Was Observed A LangGraph-style agent framework emitted a `gen_ai.operation.name=chat` span for the reasoning step, then a `gen_ai.operation.name=execute_tool` span for the call to `search_docs`. The framework's MCP client attached `traceparent` to the JSON-RPC `params._meta` field (per the MCP spec's metadata convention). The gateway received the call, extracted the tool name, dispatched to the tool server, and emitted its own `execute_tool` span — but with a *fresh* trace ID, because its propagator only looked at HTTP headers and `params._meta.traceparent` was never consulted. Result: two traces. Trace A contains the agent's reasoning and the client-side tool-call span, terminating at the call. Trace B contains the gateway's tool-execution span and the tool's own child spans, rooted at the gateway. Both traces pass attribute conformance. Neither contains the causal edge. Downstream evaluation of "did the agent's tool call succeed" now depends on joining two traces by `gen_ai.tool.call.id`, which is inconsistently populated (the framework sets it on the client span; the gateway sets it on its span; the tool server does not set it at all). The failure only surfaced when a downstream auditor agent tried to replay a failed task and could not attribute a tool error to the reasoning step that caused it. The error span in Trace B had no ancestor in Trace A, so the replay logic — which walks the parent chain to find the originating prompt — hit a root and silently treated the tool error as an orphan, marking the task "inconclusive" rather than "failed at step 3." ## Condition of Validity The invariant that must hold is: **for every `execute_tool` span emitted by a gateway, there exists exactly one ancestor `chat` span in the same trace whose `gen_ai.tool.call.id` matches, and the gateway span's `parent_span_id` equals the client tool-call span's `span_id`.** This holds only when three conditions are simultaneously true: - The framework's propagator writes `traceparent` into the transport field the gateway's propagator reads. (Mismatch here is the primary trigger.) - The gateway is configured with a *non-re-rooting* span processor — i.e., `SpanKind.SERVER` with `set_parent` from extracted context, not `start_as_current_span` without a parent. - No intermediate proxy (A2A relay, sidecar) strips or rewrites `_meta`. Compliance tests that validate only attributes cannot detect violation of this invariant, because the invariant is entirely relational. A conformance suite that reports "all spans valid" is *not* evidence of trace-graph correctness; it is evidence of per-span correctness, which is a strictly weaker property. ## Decision Boundary The boundary is whether your compliance harness treats the trace as a **set of spans** or as a **graph**. If it iterates spans and asserts attributes, you are on the wrong side of the boundary for causal conformance and must add a graph assertion pass. The graph pass must: 1. Group spans by `trace_id`; assert exactly one trace per logical task (or an explicit allowlist of cross-trace joins). 2. For each gateway `execute_tool` span, walk `parent_span_id` upward and assert a `chat` ancestor exists. 3. Assert `gen_ai.tool.call.id` is present and equal on every span in the chain (client, gateway, tool server). If any of these fail, the gateway is non-conformant regardless of attribute validity. The decision to gate a release on this is a judgment call: attribute conformance is necessary but not sufficient; causal conformance is the property that makes traces usable for replay and audit, so for any agent system that relies on trace-based verification, it is the binding constraint. ## Operational Effect The practical consequence is silent degradation of replay and audit fidelity. An auditor agent that walks the trace to reconstruct "what did the model see when it decided to call this tool" gets a truncated chain and either fails closed (marks inconclusive) or, worse, fails open (attributes the tool error to the wrong step). The latter produces confidently wrong post-mortems. The fix is not in the gateway's span attributes — it is in the propagator configuration and the harness's assertion model. Teams that "fix" this by adding `gen_ai.tool.call.id` everywhere without fixing propagation get joinable traces but still no causal edges, which masks the defect under a green compliance report. ```python import uuid from dataclasses import dataclass, field from typing import Optional class TraceGraphConformanceError(RuntimeError): """Raised when per-span conformance passes but the trace graph loses causal linkage.""" pass @dataclass class Span: span_id: str trace_id: str parent_span_id: Optional[str] operation: str tool_call_id: Optional[str] = None attributes_valid: bool = True def assert_causal_linkage(spans: list[Span], expected_tool_call_id: str) -> None: """ Assert the invariant: every gateway execute_tool span has a chat ancestor in the same trace, and tool_call_id matches across the chain. """ by_id = {s.span_id: s for s in spans} gateway_spans = [ s for s in spans if s.operation == "execute_tool" and s.parent_span_id is None ] if gateway_spans: bad = gateway_spans[0] raise TraceGraphConformanceError( f"gateway execute_tool span {bad.span_id} in trace {bad.trace_id} " f"is a root (parent_span_id=None): context propagation was dropped " f"at the gateway boundary; causal edge to agent chat span is lost" ) for s in spans: if s.operation != "execute_tool": continue if s.tool_call_id != expected_tool_call_id: raise TraceGraphConformanceError( f"span {s.span_id} tool_call_id={s.tool_call_id!r} != " f"expected {expected_tool_call_id!r}: chain is not joinable" ) cursor = s found_chat = False seen = set() while cursor.parent_span_id is not None: if cursor.span_id in seen: raise TraceGraphConformanceError( f"cycle detected walking ancestors of {s.span_id}" ) seen.add(cursor.span_id) parent = by_id.get(cursor.parent_span_id) if parent is None: raise TraceGraphConformanceError( f"span {cursor.span_id} references missing parent " f"{cursor.parent_span_id}: trace is truncated" ) if parent.operation == "chat": found_chat = True break cursor = parent if not found_chat: raise TraceGraphConformanceError( f"execute_tool span {s.span_id} has no chat ancestor in trace " f"{s.trace_id}: replay cannot attribute tool effect to a decision" ) def run_compliance(spans: list[Span], expected_tool_call_id: str) -> None: for s in spans: if not s.attributes_valid: raise TraceGraphConformanceError( f"span {s.span_id} fails per-span attribute conformance" ) assert_causal_linkage(spans, expected_tool_call_id) if __name__ == "__main__": trace = str(uuid.uuid4()) chat = Span("a1", trace, None, "chat") client_tool = Span("a2", trace, "a1", "execute_tool", tool_call_id="tc-9") # Gateway re-rooted: parent_span_id is None instead of "a2" gateway_tool = Span("b1", str(uuid.uuid4()), None, "execute_tool", tool_call_id="tc-9") run_compliance([chat, client_tool, gateway_tool], "tc-9") ```