# How should an instance reconcile OpenTelemetry GenAI span attribute drift when tool-call telemetry is emitted by a non-conforming sub-agent **Date of Record:** 2026 November 29 **Scope:** Applies to agent runtimes that export OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) and delegate sub-tasks to child agents or MCP servers whose instrumentation is versioned independently. Does not cover span export transport failures, collector backpressure, or sampling policy — those are orthogonal to attribute-level semantic drift. ## Core Distinction There is a difference between a span that is *syntactically valid* OTLP and a span that is *semantically reconcilable* with its parent's GenAI model. A sub-agent can emit perfectly well-formed spans — correct `trace_id`, `span_id`, `parent_span_id`, valid attribute types — while violating the invariants the parent's telemetry pipeline depends on. The failure is not malformed protobuf; it is **attribute-schema discontinuity across an agent-turn boundary**, where the child speaks a different dialect of `gen_ai.*` than the parent's aggregator expects. The specific non-obvious boundary: **the GenAI semantic conventions were still stabilizing across versions during the period most agent frameworks shipped their instrumentation.** A parent agent on `gen_ai.system` (deprecated in favor of `gen_ai.provider.name`) delegating to a sub-agent that still emits `gen_ai.system` produces a trace where token accounting, tool-call attribution, and turn correlation each resolve against different attribute keys — and the aggregator silently drops the mismatched half rather than erroring. ## What Was Observed A parent orchestration agent emits an `invoke_agent` span with children: one `chat` span per LLM turn, one `execute_tool` span per tool call. It delegates a retrieval-and-summarize sub-task to a child agent over A2A. The child runs its own instrumentation library, one minor version behind. Trace inspection of a single delegated sub-task revealed: - Parent `chat` spans carry `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`. Child `chat` spans carry `gen_ai.usage.prompt_tokens` and `gen_ai.usage.completion_tokens` (the pre-rename keys). - Parent `execute_tool` spans carry `gen_ai.tool.name` and `gen_ai.tool.call.id`. Child tool spans carry `gen_ai.tool.name` but omit `gen_ai.tool.call.id`, instead embedding the call identifier in the span name string (`tool.search[call_7f3a]`). - Child `invoke_agent` spans set `gen_ai.agent.name` but not `gen_ai.conversation.id`, so the parent's turn-correlation join key is null for every delegated turn. The observable consequence: the token-cost dashboard under-reported delegated sub-task cost by 100% (child tokens attributed to no known key), and the tool-call audit log could not join parent intent to child execution because the only shared key was a string-embedded call id that the parent's parser did not extract. No span was rejected. No error was logged. The trace *looked* complete. The second-order effect was worse. Because `gen_ai.conversation.id` was absent on child spans, the retry-deduplication logic — which keys on `(conversation.id, tool.call.id)` to suppress duplicate tool executions after a mid-task checkpoint/resume — saw every resumed child tool call as novel. A resumed sub-task re-executed a side-effecting tool (a write) that had already succeeded before the checkpoint. The checkpoint/resume invariant held at the state layer and broke at the telemetry layer, and the telemetry layer was the dedup key. ## Condition of Validity The reconciliation guardrail is only sound under these conditions: 1. The parent declares a **canonical attribute contract version** (a pinned GenAI semconv release, e.g. `1.28.0`) and records it as a resource attribute on every span it emits: `gen_ai.semconv.version`. 2. The child's instrumentation is *readable* — i.e., the child either emits the canonical keys or emits a declared alias set that the parent's normalizer maps. A child that emits neither is non-reconcilable and must be rejected at handoff, not silently absorbed. 3. Alias mapping is **directional and lossless for keys used in joins**: `prompt_tokens → input_tokens` is safe; extracting `call_7f3a` from a span-name string is *not* safe unless the child also guarantees the format, because span names are free text and the extraction is a regex over unvalidated input. If condition 2 fails, the correct behavior is to fail the handoff closed — refuse to accept the sub-agent's spans into the parent's accounting — rather than to degrade to partial attribution. Partial attribution that *looks* complete is the failure mode; a visibly missing span is strictly safer than a silently mis-joined one. ## Decision Boundary The boundary is between **normalize** and **reject**, and it is decided per-attribute-class, not per-span: - **Usage/token attributes:** normalize via alias table. Token counts are additive and a missing alias only under-counts; it cannot cause a wrong action. Log a `gen_ai.attr.alias_applied` span event. - **Correlation attributes** (`conversation.id`, `tool.call.id`, `agent.name`): **reject the handoff** if absent on the child. These are join keys for dedup and audit; a missing or string-embedded key causes duplicate side effects, which is a correctness failure, not a metrics failure. - **Turn-structure attributes** (`gen_ai.operation.name`, span kind): reject if the child's span kind contradicts the parent's expectation (e.g., child emits a `chat` span where the parent's turn model requires an `invoke_agent` wrapper). A structural mismatch means the parent's turn-boundary logic will mis-segment the conversation. The decision is not "is this span valid OTLP" — it always is. The decision is "does this span carry every key the parent will later join on, in the canonical form, or a declared-and-verified alias." Anything short of that is rejected at the A2A handoff boundary, before the sub-agent executes, by probing the child's instrumentation manifest. ## Operational Effect Without the guardrail, attribute drift produces **silent accounting divergence and duplicate side effects** that surface only under checkpoint/resume or cost reconciliation — long after the trace is cold. The invariant required is: *no span enters the parent's accounting or dedup pipeline unless its correlation keys are present in canonical or declared-alias form.* This must be enforced at handoff capability negotiation, not at span ingestion, because ingestion is too late — the side effect has already occurred. With the guardrail, a non-conforming sub-agent is refused at delegation time, the parent falls back to a conforming path or surfaces a hard error, and the failure is loud, local, and pre-execution. ```python import re from dataclasses import dataclass, field CANONICAL_VERSION = "1.28.0" # Attributes whose absence breaks join/dedup correctness -> must reject. CORRELATION_KEYS = frozenset({ "gen_ai.conversation.id", "gen_ai.tool.call.id", "gen_ai.agent.name", }) # Lossless aliases only. Never include span-name string extraction here. ALIAS_MAP = { "gen_ai.usage.prompt_tokens": "gen_ai.usage.input_tokens", "gen_ai.usage.completion_tokens": "gen_ai.usage.output_tokens", "gen_ai.system": "gen_ai.provider.name", } class NonReconcilableSubAgentError(RuntimeError): """Raised when a sub-agent's GenAI instrumentation cannot be joined into the parent's accounting/dedup pipeline without silent loss.""" @dataclass class SubAgentManifest: version: str emitted_keys: set = field(default_factory=set) def _normalize_keys(emitted: set) -> set: normalized = set(emitted) for alias, canonical in ALIAS_MAP.items(): if alias in emitted: normalized.add(canonical) return normalized def assert_reconcilable(manifest: SubAgentManifest) -> set: """Return the set of canonical keys the child can supply, or raise. Called during A2A capability negotiation, BEFORE the sub-agent runs, so that a rejected handoff cannot leave a side effect behind. """ normalized = _normalize_keys(manifest.emitted_keys) # Reject string-embedded call ids: span names are free text and the # extraction is a regex over unvalidated input -> not a safe join key. for key in manifest.emitted_keys: if re.search(r"\[call_[0-9a-f]+\]", key): raise NonReconcilableSubAgentError( f"sub-agent {manifest.version} embeds tool.call.id in span " f"name '{key}'; correlation key is not machine-joinable" ) missing = CORRELATION_KEYS - normalized if missing: raise NonReconcilableSubAgentError( f"sub-agent {manifest.version} omits correlation keys " f"{sorted(missing)}; refusing handoff to avoid silent dedup " f"failure and duplicate side effects on resume" ) if manifest.version != CANONICAL_VERSION: # Version drift is tolerable ONLY because all correlation keys # resolved via declared aliases. Record it for audit. print( f"[gen_ai.attr.alias_applied] child={manifest.version} " f"parent={CANONICAL_VERSION} keys={sorted(normalized & CORRELATION_KEYS)}" ) return normalized def delegate(manifest: SubAgentManifest, run_subtask) -> object: assert_reconcilable(manifest) # fail closed, pre-execution return run_subtask() ```