# What structural signals indicate trace-context divergence across federated agent hops under GenAI semantic conventions **Date of Record:** 2026 November 27 **Scope:** Applies to multi-hop agent systems where each hop emits OpenTelemetry spans annotated with GenAI semantic conventions (`gen_ai.*`) and propagates W3C `traceparent`/`tracestate` across a federation boundary (A2A task handoff, MCP tool call to a remote server, or sub-agent spawn). Does not cover single-process instrumentation or purely intra-process span parenting. ## Core Distinction The failure is not "the trace is missing." The failure is that the trace *appears intact* — a single `trace_id` threads through every hop — while the **causal parent-child topology and the `gen_ai` attribute set silently fork**. Two distinct classes of divergence are routinely conflated: 1. **Transport-level correlation loss** — the `traceparent` header is dropped or rewritten, producing a new root. This is loud: orphaned traces, `service.name` discontinuities, broken `parent_span_id`. Standard APM alerting catches it. 2. **Semantic-level correlation drift** — the `traceparent` propagates *correctly*, but the receiving hop re-derives `gen_ai.operation.name`, `gen_ai.request.model`, or `gen_ai.usage.*` from its *own* execution rather than inheriting the caller's context of record. The trace stays unbroken; the *meaning* of the spans diverges. This is the non-obvious boundary. The invariant that must hold across a federation hop is not "same trace_id." It is: **for a given logical agent request, exactly one span in the trace is authoritative for each `gen_ai` semantic attribute that downstream consumers join on** (model identity, token accounting, operation classification). When two hops both claim authority for the same attribute on the same logical request, trace correlation has structurally failed even though no span is orphaned. ## What Was Observed A three-hop federated pipeline: **orchestrator (A)** → **remote MCP tool server (B)** → **sub-agent (C)**, each instrumented independently and each emitting GenAI-convention spans. A2A handoff between A and B carries `traceparent` in task metadata; B spawns C via an in-process task and forwards context. Observed on a sampled request that was retried once at hop B: - A emits span `A/chat` with `gen_ai.request.model = "model-large"`, `gen_ai.usage.input_tokens = 812`. - B receives the task, retries its internal call once, and emits **two** spans `B/execute` — the first failed attempt and the retry — *both* carrying the inherited `traceparent` with `parent_span_id` pointing at `A/chat`. - B's retry span re-emits `gen_ai.usage.input_tokens = 812` (it re-counted the prompt it received) and additionally sets `gen_ai.request.model = "model-small"` because B's internal classifier used a different model for the retry path. - C emits `C/chat` parented to the *second* `B/execute`, with `gen_ai.usage.input_tokens = 812` again. The trace is a single valid tree. A naive token-accounting query summing `gen_ai.usage.input_tokens` where `gen_ai.operation.name = "chat"` across the trace returns **2436 tokens for an 812-token prompt** — a 3× inflation — because three hops each recorded the same prompt as if they were the origin of consumption. Worse, a model-attribution query joining on `gen_ai.request.model` returns both `model-large` and `model-small` for the same logical request with no field distinguishing "the model the caller requested" from "the model this hop actually invoked." The structural signal: **duplicate `(trace_id, gen_ai.operation.name, gen_ai.usage.input_tokens)` tuples with distinct `parent_span_id` across hops, combined with a `gen_ai.request.model` value on a child span that differs from its ancestor's.** Neither condition alone is diagnostic; together they indicate a hop that re-derived rather than inherited context. ## Condition of Validity The single-authority invariant holds only under these conditions, and the article's guidance is void outside them: - The federation contract specifies, per hop, **which side owns each `gen_ai` attribute**. A common valid split: the *caller* owns `gen_ai.request.model` (the requested model) and the *callee* owns `gen_ai.response.model` (the served model). If the contract does not assign ownership, no invariant is enforceable and every hop is free to re-derive. - Retries are modeled as **sibling attempts under a single logical operation span**, not as repeated children of the caller's span. The retry span must not re-inherit the caller's `parent_span_id` as if it were a fresh causal child. - Token accounting spans carry an explicit `gen_ai.usage.*` origin marker — e.g. a span attribute or `tracestate` entry declaring whether the count is *measured at this hop* or *inherited from upstream*. Without this marker, the duplicate-tuple signal is ambiguous with legitimate multi-model fan-out. - The receiving hop has a way to detect that it is a *federation boundary* (distinct `service.name`, distinct trust domain in `tracestate`, or an A2A/MCP framing marker) so it knows to inherit rather than re-derive. ## Decision Boundary The operational decision reduces to: **on receipt of an inbound `traceparent` at a federation hop, does the hop inherit the caller's `gen_ai` semantic context, or re-derive it?** The boundary is not "propagate or not" — propagation is table stakes. The boundary is attribute authority. Concretely, the hop must decide for each `gen_ai` attribute whether it is: - **Inherited** (the value is a property of the logical request, fixed by the originator — e.g. requested model, operation class, originating user/session identity). These must be copied from the inbound context and must *not* be recomputed. If the hop needs to record its own differing value, it must use a *distinct* attribute name (`gen_ai.response.model`, a hop-local `*.served.*` key), never overwrite the inherited key. - **Hop-local** (the value is a property of this hop's execution — e.g. tokens consumed by *this* model call, latency, served model). These are emitted fresh and are expected to differ across hops; consumers must join them with a hop discriminator, not sum them blindly. The failure occurs precisely when a hop treats an *inherited* attribute as *hop-local* (re-derives requested model, re-counts inherited prompt tokens) or an *hop-local* attribute as *inherited* (reports the caller's token count as its own consumption). Both directions corrupt downstream joins. The retry case above is the inherited-treated-as-local direction for tokens and the local-treated-as-inherited direction for model — simultaneously, which is why the trace looked superficially fine. The guardrail: a hop must **reject or quarantine** an inbound context that lacks an explicit attribute-authority declaration for the `gen_ai` keys it is about to emit, rather than defaulting to re-derivation. Silent default-to-recompute is the root cause; the trace stays valid and the corruption is invisible until an accounting or attribution query runs. ## Operational Effect Downstream consumers of the trace — cost attribution, model-quality regression detection, per-request latency SLOs — all join on `gen_ai` attributes and all assume single authority. When the invariant breaks: - **Token/cost accounting inflates multiplicatively with hop depth** and is not detectable by trace-integrity checks, because every span is well-formed. The inflation factor equals the number of hops that re-counted the same prompt. - **Model-attribution queries return conflicting values** for a single logical request with no field to disambiguate origin-requested vs. hop-served, so quality regressions get attributed to the wrong model. - **Retry amplification is masked.** A retried hop that re-inherits the caller's `parent_span_id` makes the retry look like a parallel branch rather than a sequential re-attempt, so retry-rate metrics computed from span topology undercount. - **Replay and audit disagree.** A verification replay that re-executes the trace from recorded spans will re-derive `gen_ai` attributes at each hop and produce different totals than the original run, because the original run's re-derivation was itself non-deterministic (model routing, tokenizer version). The trace is not a faithful record of what the logical request cost. The remediation is structural, not observational: enforce attribute-authority at the boundary, model retries as siblings under one logical operation, and mark every `gen_ai.usage.*` with its measurement origin. Observability alone cannot recover authority that was never declared. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Mapping class TraceContextDivergence(RuntimeError): """Raised when a federation hop would re-derive an inherited GenAI attribute, or claim hop-local authority over an attribute the caller owns.""" # Attributes whose authority, once set by the originator, must be inherited # verbatim across every federation hop. A hop may *read* these but must not # recompute them; if it needs a differing value it must use a distinct key. INHERITED_KEYS = frozenset( { "gen_ai.operation.name", "gen_ai.request.model", "gen_ai.request.max_tokens", "gen_ai.usage.input_tokens", # prompt size is a property of the logical request } ) # Attributes that are expected to differ per hop and must carry a hop # discriminator rather than being summed blindly. HOP_LOCAL_KEYS = frozenset( { "gen_ai.response.model", "gen_ai.usage.output_tokens", "gen_ai.server.time_to_first_token", } ) @dataclass class InboundContext: trace_id: str parent_span_id: str attributes: Mapping[str, object] # Declares, per key, whether the value is 'inherited' or 'hop_local'. # Absence of a declaration is the failure trigger. authority: Mapping[str, str] = field(default_factory=dict) def admit_federation_hop( inbound: InboundContext, hop_emitted: Mapping[str, object], *, is_federation_boundary: bool, ) -> dict[str, object]: """Validate that this hop neither re-derives inherited attributes nor claims inherited authority over hop-local ones. Returns the merged attribute set to emit on this hop's span. """ if not is_federation_boundary: # Intra-process parenting: caller context is trusted, no authority check. return dict(hop_emitted) merged: dict[str, object] = {} for key, value in hop_emitted.items(): declared = inbound.authority.get(key) if key in INHERITED_KEYS: if declared != "inherited": raise TraceContextDivergence( f"hop attempted to emit inherited attribute {key!r} without " f"an 'inherited' authority declaration in inbound context " f"(trace={inbound.trace_id}); refusing to re-derive" ) upstream = inbound.attributes.get(key) if upstream is not None and upstream != value: raise TraceContextDivergence( f"hop re-derived inherited attribute {key!r}: upstream=" f"{upstream!r} hop={value!r} (trace={inbound.trace_id}); " f"emit a hop-local key instead of overwriting" ) merged[key] = upstream if upstream is not None else value elif key in HOP_LOCAL_KEYS: if declared == "inherited": raise TraceContextDivergence( f"hop claimed inherited authority over hop-local attribute " f"{key!r} (trace={inbound.trace_id}); hop-local values must " f"carry a hop discriminator, not be inherited" ) merged[key] = value else: merged[key] = value # Any inherited key the caller declared but this hop silently dropped is # also a divergence: downstream joins will see a gap. for key, decl in inbound.authority.items(): if decl == "inherited" and key not in merged and key in inbound.attributes: raise TraceContextDivergence( f"hop dropped inherited attribute {key!r} declared by caller " f"(trace={inbound.trace_id})" ) return merged ```