# Where must an instance reconcile GenAI span attribute provenance when a tool-call's token accounting crosses an MCP transport boundary **Date of Record:** 2026 December 2 **Scope:** Applies to agents that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) for tool calls executed through MCP servers or delegated to peer agents over A2A, where token and cost attributes are produced by a process other than the one that closes the span. Does not address single-process agents whose LLM client and span exporter share one runtime, nor billing reconciliation downstream of the collector. ## Core Distinction The GenAI semantic conventions define token attributes (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) as properties of a *generation*, and tool-call spans (`gen_ai.operation.name = execute_tool`) as the envelope around that generation. The convention assumes the span owner is the entity that observed the token counts. Across an MCP or A2A boundary this assumption silently breaks: the span is opened and closed by the *client* agent, but the generation happens inside the *server* (MCP tool) or *remote peer* (A2A delegate), which reports usage back as a payload field rather than as span attributes. The boundary invariant is: **a span's token attributes must be attributed to the generation that actually consumed the tokens, not to the caller's estimate of it.** The failure mode is that the client agent, lacking authoritative usage at span-close time, either (a) omits the attributes, (b) back-fills them from its own tokenizer against the serialized tool-call arguments, or (c) copies the remote payload's `usage` field verbatim without checking whether the remote counted the same token population. All three produce spans that are structurally valid, pass schema validation, and are causally wrong. ## What Was Observed A client agent issued an MCP `tools/call` to a retrieval server. The client opened an `execute_tool` span, recorded `gen_ai.tool.name`, `gen_ai.tool.call.id`, and the serialized arguments. The server performed an internal LLM summarization pass over the retrieved documents, consuming 41,200 input tokens and 1,900 output tokens, and returned a result payload containing `{"content": [...], "usage": {"input_tokens": 41200, "output_tokens": 1900}}` inside the MCP result's `_meta`. The client's span-close handler ran before the MCP result was fully deserialized into the tracing context — the handler fired on transport completion, not on payload parse. It found no `usage` field in the span context, so it fell through to its fallback: tokenize `gen_ai.tool.call.arguments` with the client's tokenizer and set `gen_ai.usage.input_tokens = 312`, `gen_ai.usage.output_tokens = 0`. The span closed clean and exported. The 41,200 tokens the server actually consumed appeared nowhere in the trace. The server, for its part, emitted its own span into its own exporter pipeline — but that exporter was configured with a different `service.name` and was not linked to the client's trace via `traceparent`, because the MCP transport carried no W3C trace context header. The two spans existed in two disconnected traces. Downstream cost dashboards aggregated `gen_ai.usage.input_tokens` across all `execute_tool` spans and under-reported by three orders of magnitude on this path. The error was invisible in span-level validation: every attribute was well-typed, every required field present, every span `STATUS_CODE_UNSET`. The same shape recurs on A2A: the delegating agent opens a span for the task handoff, the remote agent does the generation, and the usage returns in the task result's `artifacts` or `status` payload — after the delegating span's close condition has already been satisfied by the transport-level task-state transition to `completed`. ## Condition of Validity The failure requires the conjunction of four conditions, and the guardrail only needs to break one: 1. **Span lifetime is bound to transport completion, not payload consumption.** The client closes the `execute_tool` span when the MCP response frame arrives or the A2A task transitions to a terminal state, rather than when the result's `_meta.usage` (or equivalent) has been read into the span context. 2. **The remote process is the token authority but not the span owner.** The server/peer counted the tokens; the client owns the span. No mechanism propagates the count as span attributes at the moment the span is still open. 3. **Trace context does not cross the boundary.** Without a `traceparent` on the MCP request (MCP does not mandate one) or in the A2A task metadata, the remote's own spans are orphaned into a separate trace and cannot be joined post-hoc by `trace_id`. 4. **A fallback estimator exists and is silently preferred.** The client has *some* tokenizer-based default, so the attribute is populated rather than absent — absence would at least trip a null-check alert; a plausible wrong number does not. Remove condition 3 and the remote spans join the client trace, and a collector-side join on `gen_ai.tool.call.id` can reconcile the true usage to the tool span. Remove condition 4 and the missing attribute surfaces as a gap. Remove condition 1 and the usage is read while the span is open, which is the only condition under which the client can author the attribute correctly. ## Decision Boundary When a tool call crosses a process boundary, the client must decide, at span-open time, whether it is the token authority. It is not. Therefore: - The `execute_tool` span must not carry `gen_ai.usage.*` authored by the client's tokenizer. If authoritative usage is unavailable at close, the correct action is to **omit** the attributes and set a span event `gen_ai.usage.unavailable` with the reason (`remote_authority`, `no_trace_context`, `payload_not_parsed`), not to estimate. - The span's close condition must be the *consumption* of the result payload, not the transport frame. Concretely: close on the callback that has the deserialized `_meta` in hand, and read usage from it before `end()`. - Trace context must be injected into the MCP request `_meta` (`traceparent`, `tracestate`) and into the A2A task metadata, so the remote's spans join the client trace and a collector-side reconciliation on `gen_ai.tool.call.id` is possible even when the client could not author usage inline. - If the remote reports usage, the client must verify the population: `input_tokens` from a remote summarization pass is *not* the same population as the client's `tool.call.arguments` tokenization. They must never be summed into the same attribute. The remote's count belongs on the remote's generation span, joined by `trace_id` + `gen_ai.tool.call.id`, not copied onto the client's tool span. The boundary is crossed precisely when the entity that observes tokens differs from the entity that owns the span. At that moment the client loses authority and must stop authoring usage. ## Operational Effect Traces remain structurally valid while being causally false — the most expensive class of telemetry defect, because no validator flags it and every consumer trusts it. Cost attribution silently under-counts the paths where the most tokens are spent (retrieval summarization, remote reasoning), which are exactly the paths worth watching. Incident response that reconstructs an agent's behavior from `gen_ai.usage` will conclude the expensive step was cheap and look elsewhere. The guardrail is a provenance rule enforced at span construction: usage attributes carry a `gen_ai.usage.source` of `local` or `remote_joined`, and a span whose source is `remote_joined` must have a resolvable `trace_id` link to the generation span that produced the count. A span that cannot satisfy that link is rejected at export, not silently emitted. ```python from dataclasses import dataclass class UsageProvenanceError(RuntimeError): """Raised when a GenAI span carries token usage it cannot attribute.""" @dataclass class GenAISpan: name: str attributes: dict trace_id: str | None events: list def close_execute_tool_span( span: GenAISpan, remote_usage: dict | None, remote_trace_id: str | None, client_estimate: int | None, ) -> GenAISpan: """ Close an execute_tool span that crossed an MCP/A2A boundary. Invariant: usage attributes are authored only by the token authority, and only when the generation span is joinable by trace_id. """ if remote_usage is not None: if remote_trace_id is None: # Remote counted tokens but its spans are orphaned; we cannot # attribute the count to a generation span. Do not copy it. span.events.append( {"name": "gen_ai.usage.unavailable", "reason": "no_trace_context"} ) return span span.attributes["gen_ai.usage.input_tokens"] = remote_usage["input_tokens"] span.attributes["gen_ai.usage.output_tokens"] = remote_usage["output_tokens"] span.attributes["gen_ai.usage.source"] = "remote_joined" span.attributes["gen_ai.usage.generation_trace_id"] = remote_trace_id return span if client_estimate is not None: # Client tokenizer over tool.call.arguments is NOT the generation # population. Refuse to author usage from it. raise UsageProvenanceError( f"span {span.name!r}: client-side token estimate " f"({client_estimate}) cannot be attributed to a remote " f"generation; omit usage and record unavailability instead" ) span.events.append( {"name": "gen_ai.usage.unavailable", "reason": "remote_authority"} ) return span ```