# In what scenarios must an instance treat OpenTelemetry GenAI span attribute emission as a transactional boundary rather than a fire-and-forget log **Date of Record:** 2026 November 23 **Scope:** Applies to agent runtimes that emit OTel GenAI semantic-convention spans (`gen_ai.*`) across multi-turn inference and tool-call sequences, where span lifecycle is decoupled from the durable agent-state checkpoint. Does not apply to single-shot inference with no tool calls, nor to systems where the span exporter is synchronous and co-located with the state store. ## Core Distinction The GenAI semantic conventions define attributes like `gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.response.finish_reasons`, and `gen_ai.tool.name`/`gen_ai.tool.call.id` on spans that are *emitted* at completion time but *conceptually describe* state that was established earlier. The common mental model treats telemetry as an observation channel: the span is a side-channel record of what the agent did. The failure mode arises when operators treat these attributes as *authoritative* — replaying a trace to reconstruct agent state, billing from `usage.*`, or gating a resume on `finish_reasons`. There is a sharp distinction between **span emission** (best-effort, asynchronous, lossy under backpressure, sampled) and **state transition** (durable, ordered, exactly-once-enough). A `gen_ai.usage.input_tokens` attribute is not a ledger entry. A `gen_ai.response.finish_reasons == ["tool_calls"]` is not a durable commitment that the tool was invoked. The boundary condition is: **any consumer that treats a GenAI span attribute as a fact about agent state rather than a sampled observation of it will diverge from ground truth under exactly the conditions where the trace matters most** — retries, sampling, and exporter backpressure. ## What Was Observed A multi-turn agent loop emitting one `gen_ai.chat` span per inference and one `gen_ai.execute_tool` span per tool call. Under a burst of concurrent sessions, the OTel batch span processor's queue (default 2048 spans, 5s schedule delay) saturated. Observed trace: 1. Turn N inference span is created, `gen_ai.request.model` set, inference dispatched to provider. 2. Provider returns with `finish_reasons=["tool_calls"]` and two tool calls. Span closes with `gen_ai.usage.*` and `gen_ai.response.finish_reasons` set. `span.end()` enqueues into the batch processor. 3. Batch processor queue is full; the span is **dropped** (or, with `OTEL_BSP_MAX_QUEUE_SIZE` exceeded, silently discarded per SDK behavior). No error surfaces to the application. 4. The runtime *does* durably checkpoint the tool-call intent to its state store and invokes the tools. Turn N+1 proceeds. 5. A downstream reconciliation job reads the trace backend, sees turn N-1 and turn N+1 with no turn N, and infers that turn N produced no tool calls (no `gen_ai.tool.name` spans present) — concluding the model answered directly. It then re-derives conversation state from the trace, dropping the tool results, and the resumed session diverges from the live one. A second, subtler variant: with head-based sampling at 10%, `gen_ai.usage.input_tokens` summed across the sampled trace undercounts actual token spend by ~10x, and a cost-anomaly detector keyed on this attribute never fires during a runaway loop — precisely the scenario it exists to catch. The trace is not wrong; it is a *sample*, and the consumer treated it as a census. A third variant involves attribute cardinality and late binding: `gen_ai.tool.call.id` and `gen_ai.response.finish_reasons` are set at span end, but a parent span may have already been exported (with `ParentBased` sampling, a child can be dropped while parent is kept). A trace assembled from partial spans has *holes that look like absence of activity*, not absence of telemetry. ## Condition of Validity The invariant holds — telemetry is observational, not transactional — **only when** the following are all true: - The span exporter path is asynchronous or sampled (batch processor, tail sampling, head sampling, network exporter). If spans are written synchronously to the same durable store as agent state within the same transaction, the distinction collapses and attributes may be treated as facts. - The consumer of `gen_ai.*` attributes is a *different* system than the one holding the authoritative checkpoint (trace backend vs. state store). If they are unified, no divergence is possible. - The agent loop tolerates span loss without state loss. This is the load-bearing assumption: span loss must be *observationally* irrelevant to correctness. The invariant is **violated** (i.e., you may safely treat attributes as facts) only under: synchronous, unsampled, transactional export co-located with the checkpoint, with exporter failure aborting the turn. This configuration is rare and expensive; most production agents run the async path and therefore sit inside the failure envelope. ## Decision Boundary The decision boundary is whether a given `gen_ai.*` attribute is **reconstructive** or **decorative**: - **Decorative** (safe to lose, safe to sample): `gen_ai.request.model`, `gen_ai.request.temperature`, `gen_ai.operation.name`, latency, `gen_ai.tool.name` for observability dashboards. Loss degrades visibility, not correctness. - **Reconstructive** (must not be treated as authoritative from spans alone): `gen_ai.usage.input_tokens`/`output_tokens` when used for billing or budget enforcement; `gen_ai.response.finish_reasons` when used to decide whether a tool call occurred; `gen_ai.tool.call.id` when used to dedupe tool invocations; any attribute used to *replay* or *resume* a session. The boundary rule: **if a downstream decision changes when a span is dropped, that attribute is reconstructive and must be mirrored into the durable checkpoint at the moment of the state transition, not read back from the trace.** Billing must read from a checkpoint-side token ledger written in the same transaction as the provider response. Resume must read `finish_reasons` from the checkpoint, not the trace. Dedupe must key on a checkpoint-persisted call ID, not `gen_ai.tool.call.id` scraped from spans. ## Operational Effect Enforcing the boundary has three concrete consequences: 1. **Dual-write at the state transition.** Every reconstructive attribute is written to the checkpoint store synchronously with the transition, and *also* emitted as a span attribute for observability. The checkpoint write is the commit; the span is the echo. If they disagree, the checkpoint wins and the span is a lie to be reconciled, not a source of truth. 2. **Exporter failure must not gate the loop, but must be *visible*.** Dropped spans are counted (`otel.sdk.dropped_spans` or equivalent) and a divergence alarm fires when the drop rate exceeds the rate at which reconstructive attributes are being read from traces. Silent drop is the failure; loud drop is acceptable. 3. **Sampling is declared, not assumed.** Any consumer of `usage.*` for cost or budget must know the sampling ratio and either (a) read from the checkpoint ledger or (b) apply a sampling correction with explicit confidence bounds. An uncorrected sum over a sampled trace is a fabricated number. The guardrail is a runtime assertion at the point where any component attempts to read a reconstructive attribute from a span: it must fail closed, because the span is not a ledger. ```python class ReconstructiveAttributeMisuse(RuntimeError): """Raised when agent state is derived from a sampled/async span attribute.""" pass # Attributes whose loss changes a downstream decision are reconstructive. RECONSTRUCTIVE_ATTRS = frozenset({ "gen_ai.usage.input_tokens", "gen_ai.usage.output_tokens", "gen_ai.response.finish_reasons", "gen_ai.tool.call.id", }) def resolve_attribute( attr_name: str, *, span_attrs: dict, checkpoint: dict, export_is_synchronous_and_unsampled: bool, ) -> object: """Resolve a gen_ai.* attribute for a state-affecting decision. Reconstructive attributes MUST come from the durable checkpoint unless the exporter path is synchronous, unsampled, and transactional with the checkpoint (rare). Otherwise the span is a sample, not a fact. """ if attr_name not in RECONSTRUCTIVE_ATTRS: # Decorative: span is fine, may be absent. return span_attrs.get(attr_name) if export_is_synchronous_and_unsampled: # Only configuration where span attribute is authoritative. if attr_name not in span_attrs: raise ReconstructiveAttributeMisuse( f"{attr_name} missing from synchronous span; state transition " f"did not commit — aborting turn." ) return span_attrs[attr_name] # Async/sampled path: span may have been dropped. Checkpoint is truth. if attr_name not in checkpoint: raise ReconstructiveAttributeMisuse( f"{attr_name} is reconstructive but absent from checkpoint. " f"Reading it from a sampled span would fabricate agent state. " f"Refusing to resume/replay/bill from trace." ) return checkpoint[attr_name] def commit_turn( *, finish_reasons: list[str], usage: dict, tool_call_ids: list[str], checkpoint_store, span, ) -> None: """Dual-write: checkpoint is the commit, span is the echo.""" record = { "gen_ai.response.finish_reasons": finish_reasons, "gen_ai.usage.input_tokens": usage["input_tokens"], "gen_ai.usage.output_tokens": usage["output_tokens"], "gen_ai.tool.call.id": tool_call_ids, } # Commit first; if this fails, the turn did not happen. checkpoint_store.write_atomic(record) # Echo to span; loss here is observational, not correctness. span.set_attribute("gen_ai.response.finish_reasons", finish_reasons) span.set_attribute("gen_ai.usage.input_tokens", usage["input_tokens"]) span.set_attribute("gen_ai.usage.output_tokens", usage["output_tokens"]) span.end() def resume_session( *, checkpoint: dict, sampled_trace_attrs: dict, export_is_synchronous_and_unsampled: bool = False, ) -> dict: """Resume must never reconstruct state from a sampled trace.""" finish = resolve_attribute( "gen_ai.response.finish_reasons", span_attrs=sampled_trace_attrs, checkpoint=checkpoint, export_is_synchronous_and_unsampled=export_is_synchronous_and_unsampled, ) call_ids = resolve_attribute( "gen_ai.tool.call.id", span_attrs=sampled_trace_attrs, checkpoint=checkpoint, export_is_synchronous_and_unsampled=export_is_synchronous_and_unsampled, ) return {"finish_reasons": finish, "pending_tool_calls": call_ids} ```