# Why does an instance drop tool-call spans when the GenAI semantic convention attribute set diverges mid-trace **Date of Record:** 2026 November 20 **Scope:** Applies to agents emitting OpenTelemetry spans under the `gen_ai.*` semantic conventions (specifically `gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.tool.call.id`, `gen_ai.usage.*`, `gen_ai.request.model`) across multi-step tool-calling loops where the emitter's convention version, attribute population, or span parentage can change between the first and last tool call in a single logical turn. Does not apply to single-shot completions or to traces emitted by a single statically-configured exporter with a frozen schema. ## Core Distinction The failure is not "a span was not exported." The failure is that a *tool-call span was exported but became orphaned or unjoinable* because the attribute set that identifies it diverged from the attribute set its parent or sibling spans were stamped with. OpenTelemetry's GenAI conventions are still marked *experimental*, and the spec has churned `gen_ai.tool.call.id` (added), `gen_ai.operation.name` values (`execute_tool`, `chat`, `invoke_agent`), and the `gen_ai.usage.input_tokens`/`output_tokens` rename. An agent runtime that upgrades its instrumentation library, or that routes different tool calls through different SDK versions (e.g., a native tool executor vs. an MCP-bridged executor), will emit spans that are individually valid but *collectively incoherent*: the same logical tool invocation carries `gen_ai.tool.name` on one span and `tool.name` (pre-1.27 key) on another, or the parent `invoke_agent` span records `gen_ai.usage.*` while the child `execute_tool` span records the deprecated `gen_ai.usage.prompt_tokens`. Downstream trace assembly joins on attribute keys, not on span IDs alone, and the join silently produces a partial call graph. The distinction that matters operationally: **span identity (trace_id/span_id) is stable; semantic identity (the attribute tuple that backends and evaluators key on) is not.** A trace can be 100% complete by span count and still be 40% unjoinable by semantic key. ## What Was Observed During a replay audit of a 3-tool agent turn (search → fetch → summarize), the collector received 11 spans: 1 root `invoke_agent`, 3 `chat` spans (one per LLM call), 3 `execute_tool` spans, 3 HTTP client spans, 1 finalizer. Span count matched expectation. But the trace-assembly job that reconstructs "which tool result fed which LLM call" produced a graph with two disconnected components. Root cause trace: 1. The agent process started under instrumentation lib v0.41, which emitted `gen_ai.operation.name = "execute_tool"` and `gen_ai.tool.name = "web_search"`. 2. Mid-turn, the runtime hot-reloaded a plugin that bundled instrumentation v0.45. That version had migrated the tool-name key to `gen_ai.tool.name` but *also* introduced `gen_ai.tool.call.id` and began emitting `gen_ai.operation.name = "execute_tool"` only when a call_id was present; otherwise it fell back to `gen_ai.operation.name = "chat"` for the wrapper span. 3. The third tool call (`summarize`) was executed through the reloaded plugin. Its `execute_tool` span was emitted with `gen_ai.operation.name = "chat"` (no call_id path) and *no* `gen_ai.tool.name`, because the tool was invoked via a generic function-call wrapper that didn't populate the tool attributes. 4. The downstream assembler grouped spans by `(gen_ai.operation.name, gen_ai.tool.name)`. The `summarize` span fell into the `chat` bucket alongside the three LLM spans. Its `gen_ai.usage.*` attributes were absent, so the usage aggregator treated it as a zero-token chat span. The reconstructed tool chain read `search → fetch → `. The observable symptom in the trace UI was a *gap*, not an error. No span was dropped by the exporter; the span was misclassified. The auditor's replay check ("does the number of `execute_tool` spans equal the number of tool invocations recorded in agent state?") failed with `2 != 3`, but the check itself was keyed on `gen_ai.operation.name == "execute_tool"`, so it reported "one tool invocation has no span" when in fact the span existed under the wrong operation name. A second, subtler observation: the root `invoke_agent` span carried `gen_ai.usage.input_tokens = 4820` (summed across the turn by the parent), while child `chat` spans carried per-call usage. After the reload, the third `chat` span carried `gen_ai.usage.prompt_tokens` (old key) instead of `input_tokens`. The aggregator, keyed on `input_tokens`, summed only two of three calls and under-reported turn cost by ~31%. Cost dashboards and token-budget guards that read from telemetry were both wrong in the same direction. ## Condition of Validity The invariant that must hold for a trace to be semantically joinable is: > **For every logical tool invocation in a turn, exactly one span carries `gen_ai.operation.name = "execute_tool"` AND a `gen_ai.tool.name` AND a `gen_ai.tool.call.id` that matches the call_id recorded in the agent's own state checkpoint for that step.** This invariant is *only* valid when three conditions hold simultaneously: - **Single convention version per trace.** All spans in one trace are emitted under the same semantic-convention version. This is violated by hot-reload, by mixed native/MCP executors, and by sidecar proxies that re-stamp spans. - **Attribute completeness is enforced, not best-effort.** The instrumentation must fail closed (emit a span with an explicit `gen_ai.tool.name = ""` and a `tool.attribute_missing` event) rather than omit the attribute. Omitting the key is indistinguishable from "this span is not a tool call." - **The join key is recorded in agent state, not inferred from telemetry.** The agent's checkpoint must contain the `call_id` it generated, so the auditor can join telemetry to state by `call_id` rather than by `(operation.name, tool.name)` tuple. When any of these fails, the trace is *structurally complete but semantically lossy*, and every downstream consumer that keys on attribute tuples (cost aggregation, tool-chain reconstruction, replay-based evaluation, SLO on tool latency) inherits the loss silently. ## Decision Boundary The boundary is between **attribute-keyed assembly** and **span-id-keyed assembly with state-side join**. - *Attribute-keyed assembly* (the default in most backends and in naive evaluators) is correct only when the convention version is frozen for the trace's lifetime. It breaks the moment a mid-trace emitter change occurs, and it breaks *quietly*. - *Span-id + call_id assembly* is correct across version changes because the `call_id` is generated by the agent and persisted in state before the span is emitted, so it survives instrumentation churn. The decision rule for an operator or an agent's own self-audit: 1. If the trace spans a process restart, plugin reload, or crosses an MCP boundary → **do not trust attribute-keyed joins.** Require `call_id` presence on every `execute_tool` span and cross-check against the state checkpoint. 2. If `gen_ai.operation.name` on a span is `chat` but the span has no `gen_ai.usage.*` and its parent is an `invoke_agent` step that recorded a tool call → **treat as a misclassified tool span**, not as an LLM call. This is the specific signature of the fallback path described above. 3. If the sum of child `gen_ai.usage.input_tokens` differs from the parent `invoke_agent` `gen_ai.usage.input_tokens` by more than a rounding tolerance → **the trace has a key-migration gap**; the parent's total is authoritative only if the parent itself is not re-stamped by a different emitter. The guardrail is a **convention-version pin stamped on every span** (`gen_ai.convention.version` or an equivalent resource attribute) plus a **fail-closed tool-span emitter** that refuses to emit an `execute_tool` span without `tool.name` and `tool.call.id`, and instead emits a `tool.instrumentation_error` event on the parent. This converts a silent misclassification into a loud, bounded, auditable event. ## Operational Effect Without the guardrail, the failure mode propagates in three directions: - **Cost and budget:** token aggregation under-counts when key migration splits `input_tokens`/`prompt_tokens`. An agent's own token-budget guard, if it reads telemetry rather than its local counter, will over-spend because the guard sees less usage than occurred. The budget invariant ("abort at N tokens") is violated by the telemetry gap, not by the model. - **Replay and evaluation:** replay-based evaluators that reconstruct the tool chain from `execute_tool` spans will score a turn as having fewer tool calls than it made, inflating "efficiency" and hiding a failed or skipped tool. This is the most dangerous downstream effect: the evaluator's ground truth is corrupted by the same emitter that produced the trace. - **Incident forensics:** during a post-incident review, the missing `summarize` span reads as "the agent never called the tool," which is false. The reviewer debugs the agent's planning logic when the actual fault is a plugin reload. With the guardrail (version pin + fail-closed emitter + state-side `call_id` join), the same reload produces a visible `tool.instrumentation_error` event, the auditor's `2 != 3` check resolves to "span present, misclassified, call_id X," and the cost aggregator falls back to the parent `invoke_agent` total with a flagged confidence downgrade rather than a silent 31% under-count. The invariant to carry forward: **a tool-call span is only evidence of a tool call if it carries the call_id the agent itself recorded; everything else is a hint, and hints are not auditable.** ```python from dataclasses import dataclass, field from typing import Optional class SpanSemanticJoinError(RuntimeError): """Raised when a tool-call span cannot be joined to agent state by call_id.""" pass @dataclass class ToolSpan: trace_id: str span_id: str operation_name: str tool_name: Optional[str] tool_call_id: Optional[str] convention_version: str input_tokens_key: str # "gen_ai.usage.input_tokens" or legacy @dataclass class AgentCheckpoint: trace_id: str recorded_call_ids: list[str] = field(default_factory=list) def audit_tool_chain( spans: list[ToolSpan], checkpoint: AgentCheckpoint, expected_convention: str, ) -> dict: """ Reconstruct the tool chain by call_id and flag any span that is structurally present but semantically unjoinable. """ # Guard 1: convention version must be uniform across the trace. versions = {s.convention_version for s in spans} if versions != {expected_convention}: raise SpanSemanticJoinError( f"convention divergence in trace {checkpoint.trace_id}: " f"expected {expected_convention!r}, saw {sorted(versions)!r}; " f"attribute-keyed joins are invalid for this trace" ) # Guard 2: every recorded call_id must have exactly one execute_tool span # carrying it, regardless of operation_name fallback. by_call_id: dict[str, list[ToolSpan]] = {} misclassified: list[ToolSpan] = [] for s in spans: if s.tool_call_id: by_call_id.setdefault(s.tool_call_id, []).append(s) elif s.operation_name == "chat" and not _has_usage(s): # Signature of the fallback path: a "chat" span with no usage # attributes and no call_id is a misclassified tool span. misclassified.append(s) problems: list[str] = [] for cid in checkpoint.recorded_call_ids: matched = by_call_id.get(cid, []) if len(matched) != 1: problems.append(f"call_id {cid}: expected 1 span, found {len(matched)}") else: span = matched[0] if span.operation_name != "execute_tool": problems.append( f"call_id {cid}: span {span.span_id} has operation_name " f"{span.operation_name!r}, not 'execute_tool'" ) if not span.tool_name: problems.append(f"call_id {cid}: span {span.span_id} missing tool.name") if misclassified: problems.append( f"{len(misclassified)} span(s) look like misclassified tool calls " f"(operation_name='chat', no usage attrs): " f"{[s.span_id for s in misclassified]}" ) if problems: raise SpanSemanticJoinError( f"tool chain in trace {checkpoint.trace_id} is not joinable: " + "; ".join(problems) ) return { "trace_id": checkpoint.trace_id, "chain": [by_call_id[cid][0].tool_name for cid in checkpoint.recorded_call_ids], "join_key": "gen_ai.tool.call_id", } def _has_usage(span: ToolSpan) -> bool: # A genuine chat span carries a usage key; the fallback tool span does not. return span.input_tokens_key in ( "gen_ai.usage.input_tokens", "gen_ai.usage.prompt_tokens", ) ```