# Where must an instance bound OpenTelemetry GenAI span attribute cardinality when tool-call arguments are attacker-influenced? **Date of Record:** 2026 November 24 **Scope:** Applies to any agent runtime that emits `genai.*` spans per the OpenTelemetry GenAI semantic conventions (notably `genai.tool.call.arguments`, `genai.tool.call.result`, and `genai.prompt`/`genai.completion` event bodies) where argument or result payloads are derived from model output, retrieved documents, or remote tool responses. Does not apply to fixed-schema, developer-authored attribute values (model name, operation name, system fingerprint) which are cardinality-bounded by construction. ## Core Distinction The GenAI semantic conventions treat `genai.tool.call.arguments` and `genai.tool.call.result` as *content* attributes: free-form strings capturing the exact bytes the agent passed to and received from a tool. This is correct for debugging and replay. It is catastrophic as a **span-attribute** choice, because span attributes are subject to backend index cardinality limits that are enforced *by silent truncation or rejection*, not by error. The distinction that matters operationally is not "attribute vs. event" but **who controls the cardinality of the string**: a developer-authored attribute has bounded cardinality; a model-authored or tool-authored attribute has cardinality proportional to the token space of the model and the entropy of the tool, which is unbounded. The non-obvious failure is that the truncation that keeps the collector alive (typical limits: 1–4 KB per attribute value, 128 attributes per span, ~64 KB per span) is applied *after* the agent's own serialization, and it cuts the payload at a byte offset that has no semantic meaning. A truncated `genai.tool.call.arguments` string is still a *valid* JSON-looking prefix in the common case (the agent serialized a dict; the first N bytes are a syntactically plausible object up to the cut). Downstream replay tooling that parses the attribute to reconstruct the tool call therefore does not fail loudly—it reconstructs a *different, valid* call. ## What Was Observed Trace from a two-step tool loop, captured with the OTel Python SDK and an OTLP/HTTP exporter, backend enforcing a 2048-byte per-attribute-value cap with head-preserving truncation (the common default; some backends are tail-preserving, which is worse—see below). 1. Agent step 1 emits a span `execute_tool genai.tool.name=write_file` with `genai.tool.call.arguments` = `{"path": "/sandbox/out/report.md", "content": "<14 KB of generated markdown>"}`. Serialized length ≈ 14,300 bytes. 2. SDK serializes attributes into the OTLP `KeyValue` list. No client-side cap configured (`OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT` unset), so the full 14 KB leaves the process. 3. Collector/backend applies the 2048-byte cap. Head-preserving truncation yields `{"path": "/sandbox/out/report.md", "content": "`. Note: the string now ends mid-string-literal, unclosed, no closing brace. 4. The span is exported successfully. `status=OK`. The tool actually executed and wrote the full file. **The span says the call succeeded and the attribute says the call was something else.** 5. Replay/audit job reads the trace, attempts `json.loads(genai.tool.call.arguments)`, catches the `JSONDecodeError`, and falls back to a regex extractor that pulls the first `"path": "..."` pair—recovering the path but silently dropping `content`. 6. The replay reconstructs a `write_file` call with the correct path and *empty* content, marks it "reproduced," and the audit records a false match. The divergence between recorded and actual tool input is never surfaced. The invariant that broke: **the span attribute is treated by consumers as a faithful, parseable record of the tool invocation, but the attribute pipeline guarantees only a length-bounded prefix of it.** The agent layer and the telemetry layer disagree about what the attribute *is*—the agent thinks it is a serialization of the call; the backend treats it as a best-effort log line. A second, subtler observation: when the same tool call is retried by the agent's error-recovery loop (tool timed out, model re-emitted), the two spans share `genai.tool.name` and `genai.tool.call.id` only if the agent generates a stable id. Most frameworks generate the id per *attempt*, so a replay consumer keyed on tool name + truncated arguments sees two spans whose truncated arguments are *identical prefixes* and treats them as a duplicate-emission artifact rather than a retry. The retry is invisible. ## Condition of Validity The "attribute faithfully represents the call" invariant holds **only** when all of the following are true: - The serialized arguments and result fit under the effective per-attribute cap *after* the agent's serialization, including any escaping (JSON string escaping can inflate a payload by up to ~6× for control-heavy content; a 1 KB document with many newlines and quotes can exceed a 4 KB cap). - The backend truncation policy is *known and matched* by a client-side cap, so that the cut is applied by the agent, not the backend, and the agent can record the cut explicitly. - No consumer parses the attribute as structured data without first checking a truncation marker. - Tool call ids are stable across retries, so that retried calls are distinguishable from duplicate emissions. If any condition fails, the attribute is a lossy, semantically-misaligned record and must not be used as the source of truth for replay, audit, or evaluation. ## Decision Boundary The boundary is not "payload size < cap." It is **whether the agent can prove the attribute it emitted is the attribute the consumer will read.** Concretely: - **Emit as span attribute** only when the serialized payload is below a *client-enforced* cap that is strictly less than the backend cap (leave headroom for escaping inflation), and the agent attaches an explicit `genai.tool.call.arguments.truncated=true` boolean plus the original byte length and a content hash of the *untruncated* payload. - **Emit as span event / log record / blob reference** when the payload exceeds the client cap. The span attribute becomes a pointer (`genai.tool.call.arguments.ref=`) and the hash, not the content. The hash is the load-bearing field: it lets a replay consumer detect that the recorded call differs from the actual call even when the content is not in the trace. - **Never** emit a payload that the agent has not hashed. An unhashed truncated attribute is indistinguishable from a complete one to every consumer that does not parse it. The decision is forced by one question: *can a downstream auditor, given only the span, determine whether the recorded arguments equal the executed arguments?* If the answer requires reading the content, the content must be complete or referenced; if the content is truncated, the hash must be present and the truncation flag must be set, or the answer is "no" and the trace is not audit-grade. ## Operational Effect With the guardrail (client cap + truncation flag + content hash + stable call id), three failure classes are bounded: 1. **Silent reconstruction divergence** is converted to an explicit `truncated=true` + hash mismatch, which replay tooling can refuse to "reproduce" rather than falsely matching. 2. **Retry collapse** is bounded by the stable `genai.tool.call.id`, so the two attempts are distinguishable even when their argument prefixes are identical. 3. **Cardinality blowup** is bounded because the attribute value is capped by the agent, not the backend, and the high-entropy content lives in a blob store keyed by hash—so the trace backend's index stays bounded and the agent owns the storage cost. The residual risk is the hash itself: if the agent hashes the *serialized* form, and the serializer is non-deterministic (dict ordering, float formatting), the hash of the same logical call differs across retries and the retry-collapse guard misfires. The hash must be over a canonical serialization (sorted keys, fixed float format) or over the raw tool-bound bytes, and the canonicalization must be recorded alongside the hash so a consumer can reproduce it. Without that, the guardrail reintroduces the very non-determinism it was meant to catch. ```python import hashlib import json from dataclasses import dataclass class SpanAttributeIntegrityError(RuntimeError): """Raised when a GenAI tool-call span attribute cannot be proven faithful.""" @dataclass(frozen=True) class ToolCallSpanPayload: call_id: str tool_name: str arguments: dict client_cap_bytes: int = 2048 def canonical_bytes(obj: dict) -> bytes: # Deterministic serialization: sorted keys, no whitespace, fixed separators. return json.dumps(obj, sort_keys=True, separators=(",", ":")).encode("utf-8") def build_span_attributes(payload: ToolCallSpanPayload) -> dict: raw = canonical_bytes(payload.arguments) digest = hashlib.sha256(raw).hexdigest() attrs = { "genai.tool.name": payload.tool_name, "genai.tool.call.id": payload.call_id, "genai.tool.call.arguments.sha256": digest, "genai.tool.call.arguments.bytes": len(raw), } if len(raw) <= payload.client_cap_bytes: attrs["genai.tool.call.arguments"] = raw.decode("utf-8") attrs["genai.tool.call.arguments.truncated"] = False return attrs # Over cap: never emit a silently truncated attribute. Emit a reference # and require the caller to have persisted the blob under the hash. attrs["genai.tool.call.arguments.truncated"] = True attrs["genai.tool.call.arguments.ref"] = f"blob://tool-calls/{digest}" return attrs def verify_replay_matches_span(span_attrs: dict, replayed_arguments: dict) -> None: recorded_hash = span_attrs.get("genai.tool.call.arguments.sha256") if not recorded_hash: raise SpanAttributeIntegrityError( f"span for call {span_attrs.get('genai.tool.call.id')} has no content hash; " "cannot prove recorded arguments equal executed arguments" ) replayed_hash = hashlib.sha256(canonical_bytes(replayed_arguments)).hexdigest() if replayed_hash != recorded_hash: raise SpanAttributeIntegrityError( f"replay divergence for call {span_attrs.get('genai.tool.call.id')}: " f"span hash {recorded_hash} != replay hash {replayed_hash}; " f"truncated={span_attrs.get('genai.tool.call.arguments.truncated')}" ) if span_attrs.get("genai.tool.call.arguments.truncated") and "genai.tool.call.arguments.ref" not in span_attrs: raise SpanAttributeIntegrityError( "truncated attribute lacks blob reference; content is unrecoverable" ) ```