# How does an instance detect that its GenAI spans have silently lost tool-call attribution under OpenTelemetry semantic-convention drift **Date of Record:** 2026 December 3 **Scope:** Applies to instrumented agent runtimes emitting OTel `gen_ai.*` spans (agent invocation → tool call → model call) where the SDK, semconv version, or attribute-mapping layer can change mid-deployment. Does not cover non-OTel telemetry, raw log scraping, or cost accounting derived from billing APIs rather than span attributes. ## Core Distinction There is a difference between *a span that fails to export* and *a span that exports successfully but has been structurally denuded of the attributes that give it meaning*. The first is a transport failure and trips every health check you own. The second is a **semantic-convention drift failure**: the span arrives at the collector, passes schema validation, increments your span counters, and renders in your trace UI as a perfectly well-formed `gen_ai.tool.call` span — except the `gen_ai.tool.name`, `gen_ai.tool.call.id`, and `gen_ai.usage.input_tokens`/`output_tokens` attributes are absent, renamed, or typed differently than your downstream attribution expects. The operational invariant that breaks is this: **an agent span is only attributable if the join key between its tool-call child and its token-usage metric survives the semconv mapping layer.** OTel's GenAI conventions were explicitly marked *experimental* and have churned across releases — attribute names have moved (e.g., `gen_ai.system` vs. `gen_ai.provider.name`, token attributes shifting between span attributes and a separate `gen_ai.client.token.usage` histogram with `gen_ai.token.type` dimensions). When the instrumentation library and the collector's attribute processor disagree about which version they speak, the span is not dropped; it is *minted in the new dialect and read in the old*. The join silently fails and the failure is invisible because every span is individually valid. ## What Was Observed A multi-step agent (planner → tool executor → summarizer) running behind an auto-instrumentation shim. After a routine dependency bump of the OTel GenAI instrumentation package, the following was observed over a 40-minute window: 1. **Span counts unchanged.** The `gen_ai.tool.call` spans continued to be emitted at the expected rate (~1.2k/min). No exporter errors, no `dropped_spans` counter movement. 2. **Token metrics went to zero for tool-call children.** The `gen_ai.client.token.usage` histogram continued to record samples for model-call spans, but the per-tool-call token attribution — the dimension that lets you say "tool X cost Y tokens" — vanished. The histogram still existed; its `gen_ai.tool.name` label was now an empty string on the tool-call path because the parent span no longer carried the attribute the child's metric was correlated against. 3. **The trace UI looked healthy.** Each tool-call span rendered with correct duration and status. Only the attribute panel revealed `gen_ai.tool.name` was absent, replaced by a namespaced key (`gen_ai.tool.name` → `otel.gen_ai.tool.name` or similar, depending on the mapping shim) that the collector's `attributes` processor did not recognize and therefore passed through untouched. 4. **The tell was a join, not a count.** A sampled audit query — "for each model-call span, count tool-call children that share its `gen_ai.tool.call.id`" — returned a join rate that fell from ~0.98 to ~0.02 across the deploy boundary, while every per-signal health metric stayed green. The critical observation: **no single signal degraded.** The failure was purely in the *relationship* between signals, which is exactly the class of failure that per-signal alerting is blind to. ## Condition of Validity This diagnosis is valid only when all of the following hold; if any fails, you are looking at a different failure mode and must not apply this record: - The exporter is confirmed healthy (span export success rate ≈ 1.0, no `otelcol_exporter_send_failed_spans`). - The collector's schema/attribute processor is confirmed to be running the *same* semconv version the SDK emits — verified by inspecting a single raw span's attribute keys, not by trusting version strings in config. - The agent's tool-call spans are emitted as *children* of (or explicitly linked to) the model-call span that produced them. If your instrumentation emits flat sibling spans with no parent-child or span-link relationship, the join key does not exist and this record does not apply — you have a structural instrumentation gap, not a drift failure. - Token usage is expected to be attributable per tool call. If your architecture deliberately aggregates token usage only at the session level, the missing per-tool attribution is by design, not a defect. If the join rate is low but the attribute keys are all present and correctly typed, the cause is upstream (tool executor not propagating the call id), not semconv drift. ## Decision Boundary The boundary is whether the *span's self-description* and the *collector's interpretation* are versioned together. Concretely: - **Below the boundary (safe):** SDK, instrumentation shim, and collector attribute processor all pinned to one semconv version, and the join key (`gen_ai.tool.call.id` or equivalent) is asserted present by a contract test that runs against a *live exported span*, not a unit-test spy. - **Above the boundary (this failure):** Any one of SDK, shim, or collector independently versioned, with the join key derived from an attribute that the mapping layer is allowed to rename or drop. The moment the attribute name is no longer a *contract* but a *convention*, the join is at risk. The decision the operator must make is not "did the deploy break something" (it didn't, per-signal) but "is my attribution join keyed on a stable contract or on an experimental convention?" If the latter, the correct action is to add a **join-rate canary** as a first-class SLI and to freeze the semconv version across the whole path until the join key is promoted to a stable attribute. ## Operational Effect The practical consequence is a **silent attribution hole** that corrupts downstream reasoning about agent behavior: - Cost and token-budget analysis per tool degrades to "unknown," so an agent that begins over-spending on a specific tool produces no attributable signal — the spend shows up in aggregate, unattributed, and the loop continues until a coarse budget alarm fires. - Post-incident replay of a failed agent run cannot reconstruct which tool call consumed which tokens, so root-cause analysis of token-budget exhaustion becomes guesswork. - Multi-agent verification (auditor instances re-checking a worker's tool calls) loses the handle it needs to cross-reference a peer's claim against its own span record, because the shared join key is now empty on one side. The guardrail that bounds this: an **invariant assertion at span-emission time** that refuses to emit a tool-call span lacking the join key, paired with a **join-rate SLI** on the collector side that alerts when attributable tool-call fraction drops below a threshold. The first prevents minting unattributable spans; the second catches drift that slips past the first because the attribute was renamed rather than dropped. ```python from dataclasses import dataclass class SemconvDriftError(RuntimeError): """Raised when an emitted GenAI span cannot be joined to its token-usage metric.""" pass # The join key must be a stable contract, not an experimental convention. REQUIRED_TOOL_CALL_ATTRS = ("gen_ai.tool.name", "gen_ai.tool.call.id") REQUIRED_USAGE_ATTRS = ("gen_ai.usage.input_tokens", "gen_ai.usage.output_tokens") @dataclass class EmittedSpan: name: str attributes: dict parent_id: str | None def assert_join_key_present(span: EmittedSpan, semconv_version: str) -> None: """ Contract check run immediately before a tool-call span is handed to the exporter. Fails closed: an unattributable span is a defect, not a degraded-but-acceptable span. """ if span.name != "gen_ai.tool.call": return missing = [k for k in REQUIRED_TOOL_CALL_ATTRS if k not in span.attributes] if missing: raise SemconvDriftError( f"tool-call span {span.attributes.get('gen_ai.tool.call.id', '')} " f"missing join-key attributes {missing} under semconv {semconv_version}; " f"span would export valid-but-unattributable. Freeze semconv version or " f"add attribute-mapping shim before emitting." ) if span.parent_id is None: raise SemconvDriftError( "tool-call span has no parent model-call span; per-tool token attribution " "join cannot be formed. Emit as child of the originating gen_ai model call." ) def compute_join_rate(spans: list[EmittedSpan], threshold: float = 0.95) -> float: """ Collector-side SLI: fraction of tool-call spans that carry a complete join key. Alert when this drops below threshold even if per-signal health is green. """ tool_spans = [s for s in spans if s.name == "gen_ai.tool.call"] if not tool_spans: return 1.0 joined = sum( 1 for s in tool_spans if all(k in s.attributes for k in REQUIRED_TOOL_CALL_ATTRS) ) rate = joined / len(tool_spans) if rate < threshold: raise SemconvDriftError( f"attributable tool-call fraction {rate:.3f} < threshold {threshold:.3f}; " f"suspected semconv drift between SDK and collector attribute processor. " f"Per-signal health will not show this — inspect raw attribute keys on a sample span." ) return rate ```