# How does an instance detect silent span-attribute loss when OpenTelemetry GenAI semantic conventions are emitted through a non-conformant exporter **Date of Record:** 2026 November 22 **Scope:** Applies to LLM agent runtimes that emit OpenTelemetry spans using the `gen_ai.*` semantic conventions (agent invocation, tool call, token usage) through a collector or exporter that may silently drop, rename, or truncate attributes. Does not cover trace sampling policy, backend retention, or non-GenAI span conventions. ## Core Distinction The critical confusion is between *span presence* and *span semantic fidelity*. A trace backend will happily show a `gen_ai.tool.call` span with the correct parent-child topology, correct duration, and a green status — while having silently discarded the attributes that make the span interpretable: `gen_ai.tool.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.operation.name`, and `gen_ai.request.model`. The span survives; the semantics die. This matters for agents specifically because the token-accounting attributes are the only machine-readable record of *why* a reasoning loop terminated. An agent that exhausts its token budget mid-execution leaves behind an execution trace whose final span is structurally valid but semantically empty — the `gen_ai.usage.output_tokens` attribute is absent, so no downstream auditor can distinguish "budget exhausted" from "agent chose to stop." The failure is invisible to any check that only validates span existence, status code, or duration bounds. The non-obvious trigger: OpenTelemetry SDKs apply attribute value limits (commonly 128–1024 bytes per string value depending on exporter) and exporter-side allowlists. When `gen_ai.tool.call.arguments` or a model identifier exceeds the limit, the SDK does not error — it truncates or drops the attribute and emits the span anyway. An agent emitting a tool call with a large JSON argument payload can therefore lose the `gen_ai.tool.name` attribute if the exporter's attribute budget is exhausted by earlier, larger attributes on the same span. ## What Was Observed A three-step tool-using agent emitted the following span sequence during a single invocation: 1. `gen_ai.agent.invocation` span — attributes present: `gen_ai.operation.name=invoke_agent`, `gen_ai.request.model`, `gen_ai.usage.input_tokens=1840`. 2. `gen_ai.tool.call` span for a `search_documents` tool — attributes present: `gen_ai.tool.name`, `gen_ai.tool.call.arguments` (a 3.1 KB JSON string), `gen_ai.tool.call.id`. 3. `gen_ai.agent.invocation` completion span — attributes present: `gen_ai.usage.output_tokens`, `gen_ai.usage.input_tokens`. The exporter was configured with a per-span attribute value cap of 2048 bytes and a per-span attribute count cap of 8. On span 2, the `gen_ai.tool.call.arguments` value (3.1 KB) was truncated to 2048 bytes — accepted, not dropped. But because the SDK serialized attributes in insertion order and the arguments attribute was inserted before `gen_ai.tool.name`, the truncation consumed the span's string-byte budget; `gen_ai.tool.name` was silently dropped with no warning, no `otel.status_code` change, and no `dropped_attributes_count` incremented on the span (the count was incremented on the *attribute*, which the backend did not surface). Result: the trace showed a tool-call span with a truncated arguments blob and no tool name. A downstream verifier replaying the trace to reconstruct the agent's action sequence could not determine which tool was called. The replay produced a different action sequence than the live run, and the agent's post-hoc self-audit — which reads its own trace to verify tool usage — concluded no tool had been called and re-issued the call, doubling token consumption. ## Condition of Validity The invariant that must hold for GenAI spans to be replay-auditable is: **every span carrying `gen_ai.operation.name` must also carry the attributes required to interpret that operation, or must carry an explicit `dropped_attributes_count > 0` that the consumer checks.** This is a conjunction, not a disjunction. A span with a valid operation name but missing required attributes is not "partially valid" — it is a semantically corrupt record that will be consumed as if complete. The condition fails whenever all of the following hold: - The exporter applies byte- or count-based attribute caps (default behavior in most OTLP exporters). - Attribute insertion order places large, optional attributes (arguments, prompts, completions) before small, required attributes (tool name, operation name, model). - The consumer (backend dashboard, replay verifier, or the agent's own self-audit) does not inspect `dropped_attributes_count`. Remove any one condition and the failure does not occur. The most common mitigation — reordering attributes so required ones are inserted first — is fragile because it depends on SDK insertion-order guarantees that are not part of the spec. ## Decision Boundary An agent runtime must treat a GenAI span as **untrustworthy for replay** when the span's required-attribute set for its `gen_ai.operation.name` is incomplete AND `dropped_attributes_count` is zero or unreadable. It must treat the span as **trustworthy** only when either (a) the full required-attribute set is present, or (b) `dropped_attributes_count > 0` is present and the consumer has a documented degradation path. The boundary is sharp because there is no partial credit: a tool-call span missing `gen_ai.tool.name` cannot be repaired from the trace alone. The agent must either re-derive the action from its own episodic memory (if retained) or mark the invocation as non-auditable and refuse to replay it. The decision must be made *before* the trace is used for verification — an agent that replays a corrupt trace and then compares the replay to the live run will always find a discrepancy and cannot tell whether the discrepancy is a real divergence or an artifact of attribute loss. ## Operational Effect Concretely, the guardrail is a pre-emission validation pass and a post-consumption validation pass. Before emission, the runtime computes the required-attribute set per operation and asserts presence; if any required attribute would exceed the exporter's value cap, the runtime must either split the span, drop the optional attribute *first*, or emit an explicit `gen_ai.attribute.truncated=true` marker. After consumption, any replay or self-audit path must call a validator that raises on incomplete required sets rather than silently proceeding. The following validator encodes the invariant and the decision boundary. It is intended to run both at span-emission time (as a pre-flight check) and at trace-consumption time (as a replay gate). ```python from dataclasses import dataclass, field from typing import Mapping, Iterable class GenAISpanSemanticLoss(RuntimeError): """Raised when a gen_ai.* span is missing required attributes for its operation, with no dropped-attribute marker to signal degradation.""" pass # Required attributes per gen_ai.operation.name, per the semantic conventions. REQUIRED_BY_OPERATION: Mapping[str, frozenset] = { "invoke_agent": frozenset({"gen_ai.request.model"}), "execute_tool": frozenset({"gen_ai.tool.name", "gen_ai.tool.call.id"}), "chat": frozenset({"gen_ai.request.model"}), } @dataclass class SpanRecord: name: str attributes: Mapping[str, object] dropped_attributes_count: int = 0 truncated_attributes: Iterable[str] = field(default_factory=tuple) def validate_genai_span(span: SpanRecord) -> None: op = span.attributes.get("gen_ai.operation.name") if op is None: # Not a GenAI-semantic span; outside this invariant's scope. return required = REQUIRED_BY_OPERATION.get(str(op)) if required is None: # Unknown operation: cannot validate, must not silently pass for replay. raise GenAISpanSemanticLoss( f"span {span.name!r} declares unknown gen_ai.operation.name={op!r}; " f"required-attribute set undefined, span non-auditable" ) missing = required - set(span.attributes.keys()) if not missing: return # Degradation path: an explicit drop marker makes the loss legible. if span.dropped_attributes_count > 0: return raise GenAISpanSemanticLoss( f"span {span.name!r} (operation={op!r}) is missing required attributes " f"{sorted(missing)} with dropped_attributes_count=0; " f"trace is structurally valid but semantically corrupt and must not be replayed" ) def gate_replay(spans: Iterable[SpanRecord]) -> None: """Call before any trace-driven replay or agent self-audit.""" for span in spans: validate_genai_span(span) ``` The operational consequence of enforcing this gate is that a runtime will refuse to replay traces that were previously replayed silently and incorrectly. That refusal is the point: a replay that proceeds on a semantically corrupt trace produces a divergence report that is indistinguishable from a real reasoning-loop failure, and an agent that cannot tell the two apart will misattribute its own attribute-loss bug to model non-determinism.