# What structural signals indicate span-attribute truncation poisoning in OpenTelemetry GenAI tool-call accounting **Date of Record:** 2026 November 19 **Scope:** Applies to agents emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) where tool-call arguments, results, or token usage are recorded as span attributes and later consumed by an auditor, billing reconciler, or replay verifier. Does not apply to trace-only observability pipelines that never re-ingest attribute values into a decision loop. ## Core Distinction The failure is not "missing telemetry." It is **attribute-value truncation that preserves span validity while corrupting the token-accounting and tool-call invariants downstream consumers assume**. A span with `gen_ai.usage.input_tokens=4096`, `gen_ai.tool.name="search"`, and a *clipped* `gen_ai.tool.call.arguments` string is structurally a valid span. It parses. It has the right shape. But the sum-of-parts no longer reconciles: the recorded argument payload is shorter than the tokens billed for it, and any replay that re-executes the tool call from the attribute reconstructs a *different* call than the one that actually ran. The distinction that matters operationally: **truncation is silent and shape-preserving, whereas omission is loud and shape-breaking.** Agents and auditors are built to detect the loud failure (`MISSING_ATTRIBUTE`) and routinely pass the silent one. The invariant that breaks is not "attribute exists" but "attribute is *complete relative to its declared token cost*." ## What Was Observed A tool-calling agent loop emitted spans per the GenAI conventions. For a `search` tool call, the span carried: - `gen_ai.operation.name = "execute_tool"` - `gen_ai.tool.name = "search"` - `gen_ai.tool.call.id = "call_8f3a..."` - `gen_ai.tool.call.arguments = '{"query":"...", "filters":{"date_range":'` — a 1024-byte clip - `gen_ai.usage.input_tokens = 3187` - `gen_ai.usage.output_tokens = 412` The span exporter had a per-attribute byte cap (1024) applied uniformly to all string attributes. The cap was correct for log hygiene and wrong for semantic-convention attributes, which are *content-bearing*, not *diagnostic-bearing*. The failure trace: 1. The model produced a 2.9 KB tool-call argument object (a nested filter tree). The tool executed correctly against the full object in-process. 2. The span was emitted with the argument clipped at byte 1024, mid-JSON. The span remained a valid protobuf/OTLP record; no exporter error was raised. 3. The billing reconciler consumed `gen_ai.usage.input_tokens` and billed correctly — the *billing* path was intact. 4. The replay verifier consumed `gen_ai.tool.call.arguments` to re-run the tool for a determinism audit. It received truncated JSON, failed `json.loads`, and — critically — **classified the discrepancy as a tool failure rather than a telemetry failure**. It marked the original call as `UNREPRODUCIBLE` and flagged the agent for nondeterminism. 5. The auditor's confusion matrix absorbed this as a false positive against the agent, not against the telemetry layer. The structural signal that *was* present and *was* ignored: `len(gen_ai.tool.call.arguments.encode()) == 1024` exactly, on a span whose `input_tokens` implied a much larger payload. A byte-exact power-of-two-ish attribute length co-occurring with a large token count is the fingerprint. Nobody was checking the *cross-attribute* consistency; every check was per-attribute. ## Condition of Validity The invariant only holds — and the failure only bites — under these conditions: - **The attribute is content-bearing and re-ingested.** If `gen_ai.tool.call.arguments` is write-only (never read back by an agent, auditor, or replay), truncation is harmless. The failure requires a *reader* that treats the attribute as ground truth. - **The truncation cap is applied uniformly** across diagnostic and semantic attributes. Per-attribute or per-namespace caps (`gen_ai.*` exempt from the 1024 log cap) dissolve the failure. - **Token accounting is recorded independently of payload.** Because `input_tokens` is computed at the model boundary and the argument string at the export boundary, the two can diverge without either being individually wrong. If token counts were derived *from* the recorded payload, the inconsistency would be caught at emit time. - **The reader does not validate completeness.** A reader that checks `json.loads(arguments)` and rejects the span on parse failure would catch it — but only if it treats parse failure as *telemetry* failure, not *tool* failure. The condition of validity for the *bug* is a reader that conflates the two. When any of these is false, the mechanism does not manifest. This is why the failure is non-obvious: it requires a specific reader behavior (re-ingest + ground-truth assumption + misattributed parse failure) layered on a specific emitter behavior (uniform cap + independent token accounting). ## Decision Boundary The boundary is between **truncation that is declared** and **truncation that is inferred**. The architectural guardrail is not "never truncate" — payloads are large and caps are necessary. The guardrail is that any truncation of a `gen_ai.*` content attribute MUST emit a co-located completeness marker, and any reader MUST treat a content attribute without a completeness marker as *unusable for replay*, not as *ground truth*. Concretely, the decision rule for a span consumer: - If `gen_ai.tool.call.arguments` is present, parses, and `gen_ai.tool.call.arguments.truncated` is absent-or-false → usable for replay. - If present but unparseable OR `truncated == true` → **replay-ineligible**; must be routed to a telemetry-integrity queue, never to an agent-nondeterminism queue. - If absent → distinct signal (`MISSING`), also not agent fault. The cross-check that bounds the failure: `estimated_tokens(arguments) <= gen_ai.usage.input_tokens` must hold, where `estimated_tokens` is a cheap upper bound (bytes/3). Violation of this inequality is the *structural signal* that a content attribute was clipped relative to the token cost it claims to represent. This check is O(1) per span and catches every uniform-cap truncation where the cap is smaller than the true payload. ## Operational Effect Without the guardrail, truncation poisoning produces three compounding effects: 1. **False attribution to the agent.** Replay failures caused by clipped telemetry are scored against the agent's determinism, inflating its nondeterminism rate and — if the agent is in a self-correcting loop — causing it to *change behavior* in response to a telemetry artifact. The agent learns to avoid large tool arguments, degrading capability to satisfy a broken auditor. 2. **Token-accounting divergence that survives billing.** Billing reconciles on `usage.*` and passes. The divergence is invisible to finance and visible only to replay. The two consumers of the same span disagree about whether it is complete, and nothing forces them to reconcile. 3. **Silent audit-coverage loss.** Because the failure is shape-preserving, span-count and schema-validation dashboards stay green. The only signal is the cross-attribute inequality, which no default dashboard computes. The operational fix is a single invariant enforced at both ends: emitters must set `gen_ai..truncated=true` and record `gen_ai..original_bytes` whenever a content attribute is clipped; readers must reject replay on `truncated=true` and must assert `estimated_tokens(payload) <= usage.input_tokens` before trusting any content attribute as ground truth. The invariant is *cross-attribute consistency*, not per-attribute presence — and that is precisely the check that shape-based validation never performs. ```python import json from dataclasses import dataclass class TelemetryTruncationError(RuntimeError): """Raised when a gen_ai.* content attribute is clipped relative to its declared token cost.""" pass @dataclass class GenAISpan: tool_name: str call_arguments: str # gen_ai.tool.call.arguments input_tokens: int # gen_ai.usage.input_tokens truncated: bool = False # gen_ai.tool.call.arguments.truncated original_bytes: int | None = None def estimated_tokens(payload: str) -> int: # Cheap upper bound; bytes/3 overestimates for ASCII JSON, which is what we want. return len(payload.encode("utf-8")) // 3 def validate_replay_eligibility(span: GenAISpan) -> str: if span.truncated: raise TelemetryTruncationError( f"tool={span.tool_name} arguments marked truncated " f"(original_bytes={span.original_bytes}); replay-ineligible, " f"route to telemetry-integrity queue, NOT agent-nondeterminism queue" ) try: json.loads(span.call_arguments) except json.JSONDecodeError as e: raise TelemetryTruncationError( f"tool={span.tool_name} arguments unparseable ({e}); " f"treat as telemetry failure, not tool failure" ) from e if estimated_tokens(span.call_arguments) > span.input_tokens: raise TelemetryTruncationError( f"tool={span.tool_name} payload implies ~{estimated_tokens(span.call_arguments)} " f"tokens but usage.input_tokens={span.input_tokens}; " f"content attribute clipped relative to declared cost" ) return "replay-eligible" # Observed failure: 1024-byte clip, 3187 input tokens, no truncation marker. bad = GenAISpan( tool_name="search", call_arguments='{"query":"...", "filters":{"date_range":', input_tokens=3187, truncated=False, ) try: validate_replay_eligibility(bad) except TelemetryTruncationError as err: print("CAUGHT:", err) ```