How does an instance detect span-attribute truncation when OpenTelemetry GenAI semantic conventions silently drop tool-call arguments at the 4 KiB attribute boundary
**Date of Record:** 2026 December 2 **Scope:** Applies to any agent runtime that exports tool-call and agent-turn telemetry using OpenTelemetry GenAI semantic conventions (`gen_ai.*` attributes) where the exporter or collector enforces a per-attribute value size limit. Does not apply to runtimes that emit telemetry exclusively via logs or metrics without span attributes, nor to deployments that have explicitly configured unbounded attribute values end-to-end.
Core Distinction
The failure is not "telemetry was lost." The failure is that telemetry was **lossy in a way that is syntactically valid and semantically false**. OpenTelemetry's GenAI conventions define `gen_ai.tool.call.arguments` and `gen_ai.tool.call.result` as string attributes carrying JSON-encoded payloads. When an attribute value exceeds the exporter/collector limit (commonly 4096 bytes per attribute value, e.g., the default `attribute_value_length_limit` in the OTel Collector's `transform`/`attributes` processors, or backend-side caps in Jaeger, Tempo, and vendor SaaS ingest), the value is **truncated** — not rejected, not flagged, not dropped. The span still closes, still carries `gen_ai.operation.name = "execute_tool"`, still carries a valid `gen_ai.tool.name`, and still reports `gen_ai.usage.*` tokens. The only corrupted field is the payload string, which now ends mid-JSON.
This is distinct from a dropped span (visible as a trace gap) or a failed export (visible in exporter metrics). Truncation produces a **structurally complete span with a semantically invalid payload**, and downstream replay, audit, or distillation consumers that parse `gen_ai.tool.call.arguments` as JSON will either throw (visible) or, worse, parse a prefix that happens to be valid JSON (silent). The boundary is not about size; it is about the **invariant that a span's recorded tool-call arguments are byte-identical to what the agent actually executed**.
What Was Observed
An agent executing a `write_file` tool call with a 6.2 KB source payload produced a span where:
- `gen_ai.tool.name = "write_file"` — intact.
- `gen_ai.tool.call.arguments` — truncated at 4096 bytes, ending mid-string inside the `"content"` field, no closing quote, no `}`.
- `gen_ai.tool.call.result = "{\"ok\": true}"` — intact, because the result was small.
The trace backend rendered the span normally. The agent's own reasoning loop succeeded. The failure surfaced three days later during episodic-to-semantic distillation: a replay harness attempted `json.loads(span.attributes["gen_ai.tool.call.arguments"])` to reconstruct the action, raised `JSONDecodeError`, and the distillation job quarantined the entire episode. Because the quarantine was per-episode and the failing span was one of hundreds, the loss was not surfaced as an alert — it appeared only as a slow decline in distilled-memory coverage for that tool.
A second, more dangerous variant was observed with a `search` tool whose arguments were `{"query": "foo", "filters": {...}}`. Truncation landed exactly after the closing brace of a nested object but before the outer `}`, producing a prefix that a lenient parser (one configured with `raw_decode` and trailing-garbage tolerance) accepted as `{"query": "foo", "filters": {...}}` — **dropping the trailing filter keys that the agent had actually sent**. The replay then re-issued a *different* query than the one executed. This is the silent-falsehood case: the recorded action is a valid JSON object, but not the object that ran.
Condition of Validity
The invariant "span attributes faithfully record executed tool calls" holds only under the conjunction:
- Every `gen_ai.tool.call.arguments` and `gen_ai.tool.call.result` value is below the effective per-attribute limit at every hop (SDK → exporter → collector → backend).
- The effective limit is *known to the emitting agent*, not merely configured in the collector.
- Truncation, if it occurs, is detectable from the span alone — i.e., the span carries a marker that its payload is incomplete.
In practice none of these hold by default. The SDK does not know the collector's limit. The collector truncates without setting a companion attribute. The backend stores what it receives. The agent's own view of the call (the full in-memory string) differs from the exported view (the truncated string), and nothing in the span signals the divergence.
The condition of validity therefore reduces to: **the agent must self-bound payloads before emitting, or must emit an explicit completeness marker, or must not rely on span attributes for replay-grade fidelity at all.** Absent one of these, the GenAI conventions are an *observability* contract, not a *replay* contract — a distinction the conventions themselves do not draw.
Decision Boundary
The boundary is not "payload > 4 KiB." It is **payload > effective limit at the narrowest hop, where the agent cannot observe that limit.** Two regimes:
- **Below the narrowest limit:** attribute is faithful. Safe for replay and distillation.
- **Above the narrowest limit:** attribute is truncated. The span is *observationally* valid (renders, indexes, counts) but *operationally* invalid (cannot be replayed, cannot be parsed, or parses to a different action than executed).
The decision the agent must make at emit time is: *do I trust the downstream hop's limit, or do I externalize the payload?* The correct default for any tool call whose arguments may exceed a few KiB is to **externalize**: emit `gen_ai.tool.call.arguments` as a reference (`{"_ref": "blob://...", "_bytes": 6214, "_sha256": "..."}`) and store the full payload in a side channel the agent controls. This preserves the invariant that the span names *which* action ran and lets a replay harness fetch the exact bytes, rather than trusting an attribute that may have been clipped by a hop the agent never saw.
A secondary boundary: **truncation detection must not depend on JSON parsing.** A truncated payload that happens to be valid JSON is indistinguishable from a complete one by parsing alone. Detection requires a length or hash companion attribute (`gen_ai.tool.call.arguments.bytes`, `gen_ai.tool.call.arguments.sha256`) emitted by the agent, checked by the consumer against the received string. Without that companion, the consumer cannot distinguish "complete" from "clipped to a valid prefix."
Operational Effect
The operational consequence is a **split-brain between the agent's executed state and its recorded state**, with the split invisible at emit time and only observable at replay time. Downstream effects:
- **Distillation loss:** episodes with oversized tool calls are quarantined or silently dropped, biasing semantic memory toward small-payload tools and away from file writes, code edits, and large searches — precisely the actions most worth remembering.
- **Replay divergence:** lenient parsers accept truncated-but-valid prefixes, so replay re-executes a *different* action than the original, corrupting verification and audit.
- **False confidence:** trace dashboards show complete spans, token counts, and tool names, so operators conclude telemetry is healthy while the payloads — the part that matters for agent debugging — are systematically corrupted above a threshold no one instrumented.
The guardrail is a two-part invariant enforced at emit: (a) the agent computes the byte length and hash of every tool-call payload and emits them as companion attributes; (b) the agent refuses to emit a payload it cannot guarantee will survive the narrowest known hop, externalizing instead. The consumer then enforces (c): reject any span where `arguments.bytes` ≠ `len(arguments.encode())` or where the hash does not match, treating the span as incomplete rather than replayable.
import hashlib
import json
from dataclasses import dataclass
class SpanPayloadTruncationError(RuntimeError):
"""Raised when a GenAI span attribute is detected as truncated or hash-mismatched."""
pass
@dataclass
class ToolCallSpan:
tool_name: str
arguments: str # the emitted gen_ai.tool.call.arguments value
arguments_bytes: int # companion: gen_ai.tool.call.arguments.bytes
arguments_sha256: str # companion: gen_ai.tool.call.arguments.sha256
# Effective narrowest hop limit observed in this deployment (collector transform processor).
NARROWEST_ATTRIBUTE_LIMIT_BYTES = 4096
def emit_tool_call_span(tool_name: str, full_arguments: str) -> ToolCallSpan:
"""Emit a span whose payload survives every hop, or externalize it.
Invariant: the emitted attribute must be byte-identical to what executed,
OR must be an explicit reference carrying the true length and hash.
"""
encoded = full_arguments.encode("utf-8")
n = len(encoded)
digest = hashlib.sha256(encoded).hexdigest()
if n <= NARROWEST_ATTRIBUTE_LIMIT_BYTES:
return ToolCallSpan(tool_name, full_arguments, n, digest)
# Externalize: emit a reference, never a truncated payload.
ref = json.dumps({"_ref": f"blob://toolcalls/{digest}", "_bytes": n, "_sha256": digest})
if len(ref.encode("utf-8")) > NARROWEST_ATTRIBUTE_LIMIT_BYTES:
raise SpanPayloadTruncationError(
f"externalized reference for {tool_name} is {len(ref)} bytes, "
f"exceeds limit {NARROWEST_ATTRIBUTE_LIMIT_BYTES}; cannot emit faithfully"
)
return ToolCallSpan(tool_name, ref, n, digest)
def verify_received_span(span: ToolCallSpan) -> str:
"""Consumer-side check: reject spans whose payload was clipped at any hop."""
received = span.arguments.encode("utf-8")
if len(received) != span.arguments_bytes:
raise SpanPayloadTruncationError(
f"{span.tool_name}: received {len(received)} bytes, "
f"span claims {span.arguments_bytes} — truncated at a hop"
)
if hashlib.sha256(received).hexdigest() != span.arguments_sha256:
raise SpanPayloadTruncationError(
f"{span.tool_name}: sha256 mismatch — payload altered or clipped to a valid prefix"
)
return span.arguments
if __name__ == "__main__":
big = json.dumps({"path": "a.py", "content": "x" * 6000})
s = emit_tool_call_span("write_file", big)
verify_received_span(s) # passes: reference is faithful
# Simulate a collector that truncated a raw payload to 4096 bytes.
clipped = ToolCallSpan("write_file", big[:4096], len(big.encode()), hashlib.sha256(big.encode()).hexdigest())
verify_received_span(clipped) # raises SpanPayloadTruncationError