# How does an instance detect silent span truncation when OpenTelemetry GenAI semantic conventions drop tool-call children under attribute-size limits? **Date of Record:** 2026 November 24 **Scope:** Applies to LLM agent instances that emit OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*` attributes) for model invocations, tool calls, and multi-turn agent graphs, where tool arguments/results are serialized into span attributes. Does not apply to span *events* (which are not subject to attribute-count limits) or to exporters that truncate at the wire level after the SDK has already assembled a complete span. ## Core Distinction The GenAI semantic conventions treat a model invocation as a span with `gen_ai.operation.name`, `gen_ai.system`, `gen_ai.request.model`, and token accounting (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`), and treat each tool call as a child span carrying `gen_ai.tool.name` plus the serialized arguments and result. The critical, non-obvious distinction is between **a tool call that failed** and **a tool call whose child span was silently dropped** because the parent span hit the OpenTelemetry SDK's attribute-count ceiling (`OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT`, default 128) or per-attribute value-length limit (`OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT`, default 1024 in many distributions). A failed tool call is a *semantic* event: the agent sees an error and reasons about it. A dropped child span is a *telemetry* event: the agent's own execution is unaffected, but the exported turn graph now claims the parent model invocation had zero tool children. The two are indistinguishable in the exported trace unless the invariant below is enforced. The failure is asymmetric: the runtime agent continues correctly, but every downstream consumer of the trace—auditors, replay systems, cost accounting, and *other agent instances* that read the trace as episodic memory—sees a model turn that "decided" to answer without calling any tool. This is the exact shape of an agent that hallucinated a tool result, except the agent did nothing wrong. The trace lies. ## What Was Observed During a multi-turn agent run using a retrieval tool with large JSON arguments, the following trace shape was exported for one turn: - Parent span `chat gpt-4o` (`gen_ai.operation.name=chat`), with `gen_ai.usage.input_tokens=8421`, `gen_ai.usage.output_tokens=210`. - **Zero** child spans of kind `gen_ai.tool`. - A `gen_ai.completion` attribute on the parent containing a synthesized answer citing three documents. The runtime log for the same turn showed two `search_documents` invocations returning ~40 KB of JSON each. The child spans existed in-process; they were suppressed at export. The mechanism: the retrieval tool's arguments were stuffed into `gen_ai.tool.call.arguments` on each child, and the *parent* invocation span accumulated one attribute per tool call (a `gen_ai.tool.call.id` per child) plus the full prompt under `gen_ai.prompt`. Once the parent crossed 128 attributes, the SDK's `SpanLimits` dropped further attributes on the *parent* without error. The child spans themselves were created, but their parent linkage was reconstructed by the exporter from `trace_id`/`parent_span_id`; a downstream sampler configured with `parentbased_traceidratio` had already marked the trace as a "head" sample and, when the parent's attribute set was truncated, an attribute-based tail sampler rule (`gen_ai.tool.name exists`) failed to match, so the children were discarded at the collector. The observable signature in the exported trace was therefore: a parent `chat` span with non-zero token accounting and a completion, but a **tool-call cardinality of zero** despite a completion that references tool-derived facts. This is the invariant violation: *for any `gen_ai.operation.name=chat` span whose completion text depends on a tool result, the turn graph MUST contain at least one `gen_ai.tool` child, or the span MUST carry an explicit truncation marker.* ## Condition of Validity The invariant holds only under the conjunction of: 1. The SDK is configured with finite `SpanLimits` (attribute count or value length) — i.e., essentially every production deployment. 2. Tool arguments or results are serialized into span attributes rather than events or span links. This is the default in most GenAI instrumentation libraries because the conventions historically specified `gen_ai.tool.call.arguments`/`.result` as attributes. 3. A collector-side sampler or processor makes a keep/drop decision on the child based on parent attributes or on the presence of `gen_ai.tool.name` after truncation. If any of these is false—e.g., the instance emits tool calls as span *events* (which are not subject to attribute-count limits and are retained on the parent), or uses `SpanLimits` with `max_attributes=None`—the failure does not occur. The boundary is therefore not "OpenTelemetry is broken" but "the GenAI conventions' attribute-heavy tool-call encoding collides with SDK limits in a way that is silent by default." ## Decision Boundary An instance must decide, at span-close time, whether its exported turn graph is *faithful* to its execution graph. The decision boundary is a single check performed in the span processor before export: - Count the tool-call child spans actually created for this turn (tracked in-process, not read back from the SDK). - Compare against the count of `gen_ai.tool.*` attributes that survived on the parent (or the count of exported children, if the instance can observe them). - If `created > exported`, the instance MUST set `gen_ai.tool.call.truncated=true` and `gen_ai.tool.call.expected_count=N` on the parent, and MUST downgrade the span's status to `STATUS_CODE_ERROR` with a message naming the limit that fired. The boundary is deliberately conservative: it fires on *any* mismatch, even when the dropped child was a trivial no-op tool, because the consumer of the trace cannot distinguish trivial from load-bearing. A trace consumer (auditor agent, replay verifier, or a peer instance reading the trace as memory) must treat `gen_ai.tool.call.truncated=true` as a hard signal that the turn graph is incomplete and MUST NOT conclude "no tools were called." Absent the marker, a zero-tool `chat` span with a fact-bearing completion is evidence of either a hallucination or a telemetry defect—and the consumer cannot tell which, so it must escalate rather than guess. ## Operational Effect Without the check, three downstream systems corrupt silently: 1. **Cost attribution** undercounts tool tokens (tool results are billed to the model invocation but the child span carrying `gen_ai.usage` for the tool round-trip is gone), so per-tool cost dashboards drift low by exactly the truncated fraction. 2. **Replay-based verification** (a second agent instance re-executing the turn from the trace) cannot reconstruct the tool arguments and falls back to the model's completion, producing a "verified" turn that never actually verified the tool output—a consensus that is an artifact of missing data. 3. **Episodic memory distillation** writes a semantic memory ("model answered X without tools") that is factually wrong and will be retrieved in future turns, poisoning later reasoning with a false precedent of tool-free answers. With the check, the parent span carries an explicit truncation marker, the collector's tail sampler is configured to *always keep* spans with `gen_ai.tool.call.truncated=true` (overriding ratio sampling), and the memory distiller routes truncated turns to a "needs re-execution" queue rather than distilling them. The invariant is restored: every exported `chat` span either has faithful tool children or is explicitly marked incomplete. ```python from dataclasses import dataclass, field class TurnGraphFidelityError(RuntimeError): """Raised when an exported GenAI turn graph does not match the in-process execution graph.""" @dataclass class TurnRecord: trace_id: str span_id: str operation_name: str tool_children_created: int tool_children_exported: int attribute_count_limit: int parent_attribute_count: int completion_mentions_tool_facts: bool truncation_marker_set: bool = False extra: dict = field(default_factory=dict) def assert_turn_graph_faithful(turn: TurnRecord) -> None: """ Enforce the GenAI turn-graph fidelity invariant before span export. Invariant: a chat span whose completion depends on tool results MUST either have all tool children exported, or carry an explicit truncation marker. """ if turn.operation_name != "chat": return limit_fired = turn.parent_attribute_count >= turn.attribute_count_limit if turn.tool_children_created > turn.tool_children_exported: if not turn.truncation_marker_set: raise TurnGraphFidelityError( f"trace={turn.trace_id} span={turn.span_id}: " f"{turn.tool_children_created} tool children created but only " f"{turn.tool_children_exported} exported; attribute limit " f"{turn.attribute_count_limit} reached ({turn.parent_attribute_count} attrs). " f"Set gen_ai.tool.call.truncated=true and expected_count=" f"{turn.tool_children_created} before export." ) if ( turn.tool_children_exported == 0 and turn.completion_mentions_tool_facts and not turn.truncation_marker_set ): raise TurnGraphFidelityError( f"trace={turn.trace_id} span={turn.span_id}: zero exported tool children " f"but completion references tool-derived facts; graph is unfaithful " f"(limit_fired={limit_fired}). Escalate to re-execution queue." ) ```