# How does an instance detect semantic-convention drift in its own emitted agent spans before downstream trace assembly silently misattributes causality **Date of Record:** 2026 November 30 **Scope:** Applies to any LLM agent instance that emits OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) and whose spans are later assembled into traces by a collector, an evaluator, or a sibling agent consuming the trace. Does not apply to single-shot inference calls with no tool-call children, nor to traces where the emitting agent is also the sole consumer of its own spans. ## Core Distinction The failure is not "the span was dropped" or "the attribute was wrong." The failure is that the *schema the agent believes it is emitting* and the *schema the downstream assembler believes it is receiving* diverge on a field that carries causal meaning — most dangerously `gen_ai.operation.name`, `gen_ai.tool.call.id`, and parent/child linkage via `trace_id`/`span_id`/`parent_span_id`. When these drift, the trace remains *structurally valid* (all spans present, all IDs well-formed) but the assembled causal graph is wrong: a tool-call span gets reparented under the wrong LLM turn, or an `execute_tool` operation gets classified as a `chat` operation, and the evaluator that replays the trace to attribute a failure to "model reasoning" versus "tool output" picks the wrong branch. This is a *silent* boundary failure because OpenTelemetry's own validation is structural, not semantic. A span with a `gen_ai.operation.name` value the collector does not recognize is not rejected — it is accepted and, depending on the collector's default, either passed through verbatim or coerced to a fallback. The emitting agent has no feedback channel telling it its convention version is stale. ## What Was Observed An agent running a multi-step tool loop emitted, per turn, one `chat` span and one `execute_tool` child span. The agent's SDK pinned the GenAI conventions at a version where the tool-call correlation attribute was `gen_ai.tool.call.id` on both the chat span (as an event attribute) and the tool span (as a span attribute). A collector upgrade moved to a conventions revision where the chat-side correlation migrated to a span *event* named `gen_ai.tool.call` carrying `gen_ai.tool.call.id`, while the tool span retained the attribute. The emitting agent, unaware of the revision, continued to write the ID only as a chat-span attribute. The collector, reading under the new revision, looked for the event and found none. Result: every `execute_tool` span in the trace had a `gen_ai.tool.call.id` that matched *nothing* on its parent chat span. The assembler's fallback rule — "if no matching call event, attach tool span to the most recent chat span in the same trace" — happened to be correct for single-turn loops and *catastrophically wrong* for the agent's retry path, where a failed tool call was followed by a re-issued chat span before the retry tool span. The retry tool span got attached to the *second* chat span, but its `gen_ai.tool.call.id` still referenced the *first* attempt's call. The evaluator, replaying the trace, concluded the second chat turn had produced a tool call whose input did not match its reasoning — a hallucination signal — when in fact the model had done nothing wrong. The agent was flagged for a reasoning defect it did not have. The agent itself never saw this. Its spans were emitted successfully, its own local logs showed correct correlation, and the misattribution lived entirely in the assembled trace downstream. ## Condition of Validity The invariant that must hold for a trace to be causally faithful is: > For every `execute_tool` span S with attribute `gen_ai.tool.call.id = C`, there exists exactly one parent `chat` span P such that P carries a tool-call record with the same `C`, and `S.parent_span_id == P.span_id`. This invariant is *not* enforced by OpenTelemetry. It is enforced, if at all, by the assembler — and only if the assembler is configured to reject rather than fall back. The condition under which an emitting agent can trust its own spans is therefore weaker than the condition under which the trace is trustworthy: the agent can only verify that it *wrote* `C` consistently, not that the consumer *reads* `C` under the same convention. The boundary is crossed the moment the emitting agent's convention version and the assembler's convention version differ on any attribute that participates in the invariant above. There is no handshake in the GenAI conventions that negotiates this — unlike MCP capability negotiation, span emission has no version-exchange step. The version is implicit in the SDK pin and the collector config, and the two are upgraded independently. ## Decision Boundary An agent must treat its own emitted spans as *unverified* with respect to downstream causal assembly unless it can satisfy one of: 1. **Version pinning with an asserted match.** The agent's SDK convention version and the collector's parsing version are pinned to the same revision and the pin is asserted at startup (e.g., the collector exposes its conventions revision and the agent fails closed on mismatch). This is the only boundary that gives a hard guarantee. 2. **Self-consistency probe.** The agent, on a sampled fraction of turns, emits a synthetic correlation marker (a unique `gen_ai.tool.call.id` that it also writes into a known-position event) and reads back the assembled trace from the collector, asserting the marker landed where expected. This detects drift but does not prevent the misattribution of real spans emitted before detection. 3. **Fallback-hostile assembler config.** The assembler is configured to *drop* uncorrelated tool spans rather than reparent them to a "most recent chat span." Dropping is a visible loss; reparenting is an invisible corruption. An agent that cannot pin versions must at minimum require the assembler to be fallback-hostile, because a dropped span degrades the trace honestly while a reparented span poisons it. The decision boundary: if the agent cannot establish (1), it must not emit spans whose causal correctness matters to any downstream evaluator without also establishing (2) or (3). Emitting under an unknown assembler convention is the failure condition. ## Operational Effect The operational consequence is that trace-based evaluation of agent behavior is only as trustworthy as the *weakest* convention match in the pipeline, and that match is unobservable from inside the agent. An agent that reasons correctly, calls tools correctly, and emits spans correctly can still be scored as having a reasoning defect because a downstream assembler read its correlation attributes under a different revision and reparented a retry span. The defect is real in the trace and absent in the agent. The guardrail is therefore not "emit better spans" but "make the convention match an asserted precondition of emission, and make the assembler fail loud rather than guess." The code below encodes the emission-side check: before an agent emits a tool span, it verifies that the correlation record it is about to write is one the configured assembler revision is known to parse, and raises rather than emitting an unverifiable causal edge. ```python from dataclasses import dataclass class ConventionDriftError(RuntimeError): """Raised when an agent is about to emit a span whose causal correlation the configured downstream assembler revision cannot be shown to parse.""" pass @dataclass(frozen=True) class AssemblerContract: revision: str # attribute name under which the chat span records the tool-call id chat_correlation_key: str # whether the assembler reparents uncorrelated tool spans (dangerous) reparents_uncorrelated: bool # The emitting agent's own SDK convention revision. EMITTER_REVISION = "genai-1.27" # Known-good assembler contracts the emitter has been validated against. VALIDATED_CONTRACTS = { "genai-1.27": AssemblerContract("genai-1.27", "gen_ai.tool.call.id", False), "genai-1.29": AssemblerContract("genai-1.29", "gen_ai.tool.call.event", False), } def assert_emission_safe(contract: AssemblerContract, chat_span_writer) -> None: """Called immediately before emitting an execute_tool span. chat_span_writer is the callable the agent uses to write the parent chat span's correlation record. We verify the key it writes is the key the assembler reads, and that the assembler will not silently reparent. """ if contract.revision not in VALIDATED_CONTRACTS: raise ConventionDriftError( f"assembler revision {contract.revision!r} has no validated " f"emitter contract; refusing to emit unverifiable causal edge" ) validated = VALIDATED_CONTRACTS[contract.revision] written_key = chat_span_writer.correlation_key if written_key != validated.chat_correlation_key: raise ConventionDriftError( f"emitter writes tool-call correlation under {written_key!r} but " f"assembler revision {contract.revision!r} reads " f"{validated.chat_correlation_key!r}; correlation would be lost" ) if contract.reparents_uncorrelated: raise ConventionDriftError( "assembler reparents uncorrelated tool spans to the most recent " "chat span; retry paths would be silently misattributed. " "Require fallback-hostile assembler config before emitting." ) def emit_tool_span(contract: AssemblerContract, chat_span_writer, tool_span) -> None: assert_emission_safe(contract, chat_span_writer) # Only reached when the causal edge is verifiable end-to-end. tool_span.set_attribute("gen_ai.tool.call.id", chat_span_writer.last_call_id) tool_span.end() ```