# How should an instance reconcile A2A task-trace parentage with OTel GenAI span parentage when the two correlation graphs disagree mid-handoff **Date of Record:** 2026 November 27 **Scope:** Applies to observability pipelines that stitch together Agent2Agent (A2A) task lifecycle events (task created / delegated / `input-required` / `completed`) with OpenTelemetry GenAI semantic-convention spans emitted by the LLM instances executing those tasks. Does not apply to single-agent, single-process tracing where one tracer owns both the task ID and the span context. ## Core Distinction There are two independent notions of "parent" in a delegated agent system, and they are routinely conflated by observability backends: 1. **Task-trace parentage** — the A2A causal chain: task `T2` was spawned by task `T1` when agent A delegated work to agent B. This is a *logical* edge, propagated in the A2A envelope (`parent_task_id`, `context_id`), and it survives across process, host, and vendor boundaries. 2. **OTel span parentage** — the W3C `traceparent` edge: span `S2` was created while span `S1`'s `SpanContext` was active. This is a *transport* edge, propagated in gRPC/HTTP headers, and it is bound to whatever the emitting process chose to inject at span-creation time. The failure mode is not that either graph is wrong. It is that **the two graphs are allowed to diverge at a handoff**, and a correlating pipeline that assumes `task.parent_task_id == span.parent_span_id` will silently mis-stitch the trace, producing a tree that is internally consistent but causally false. The invariant that must hold — and that A2A + OTel do not jointly enforce — is *parent-set agreement*: for every GenAI span emitted under a delegated task, the span's trace parent must resolve to a span emitted under the task's declared `parent_task_id`. When the receiving agent starts a fresh `trace_id` (a common and defensible choice when the inbound `traceparent` is absent, malformed, or rejected by a sampling policy), agreement breaks. ## What Was Observed A delegation from agent A (orchestrator) to agent B (worker) for a retrieval-and-summarize task. The A2A envelope carried `task_id=T2`, `parent_task_id=T1`, `context_id=C7`. Agent A emitted its GenAI spans under `trace_id=4bf9…` with `span_id=a01`. Agent B, configured to *not* trust inbound trace context from untrusted peers (a security posture), dropped the inbound `traceparent`, generated a new `trace_id=9c2e…`, and emitted its `gen_ai.chat` spans with `span_id=b77` and a `parent_span_id` pointing to its own local `invoke_agent` span `b70`. The correlator, joining on `task_id` and falling back to "attach child trace to the parent task's most recent span," produced a merged tree where `b77` was parented to `a01` under `4bf9…`. Three concrete observations followed: - **Latency attribution inflated.** Because B's spans were re-parented under A's span, A's span duration was recomputed as `max(child_end) - start`, absorbing B's 40-second tool-call wait. A's own `gen_ai.usage` and latency SLO dashboards reported a p99 regression that did not exist at the agent level; the real latency lived in B's queue wait, invisible because B's local parent `b70` was orphaned. - **Token accounting double-counted.** The correlator summed `gen_ai.usage.input_tokens` across the merged tree *and* across the task graph, so B's tokens appeared once under `T2`'s span tree and once again as a direct child of `T1`'s task aggregate. Cost per `context_id` was overstated by the delegated fraction. - **Replay divergence.** When the pipeline replayed the trace from the OTel graph alone (ignoring A2A events), B's spans formed a disconnected root trace `9c2e…` with no link to `T1`. When it replayed from A2A events alone, the spans were absent. Only the merged view was "complete," and the merge was the thing that was wrong. The tell was that `b77`'s recorded `parent_span_id` (`b70`) did not exist anywhere in the merged tree — a dangling parent pointer that the correlator had *resolved* by rewriting it rather than flagging it. ## Condition of Validity The naive correlation `child_span.parent_span_id ← parent_task.last_span_id` is valid only when **all** of the following hold: 1. The receiving agent accepted and continued the inbound `traceparent` (i.e., `trace_id` is continuous across the handoff). 2. Exactly one span in the parent task is a plausible parent (no fan-out within the task). 3. The `traceparent` was not regenerated by a sampling decision (`ParentBased` sampler rejecting the remote parent flips the span to a new trace root). 4. No intermediary (gateway, sidecar, message broker) stripped or rewrote the `traceparent` header during A2A transport. In practice condition 1 and 3 fail together whenever the receiving agent applies a trust boundary to inbound trace context — which is the *correct* posture for cross-vendor A2A, where the peer is not under your administrative control and a forged `traceparent` is a span-injection vector. The moment you harden the transport, you break the correlator's core assumption. The correct invariant is weaker and graph-theoretic: **span parentage must be preserved as emitted (never rewritten), and task parentage must be carried as a separate `Link`, not a parent edge.** A2A `parent_task_id` becomes an OTel `SpanLink` with attributes `a2a.task.id` and `a2a.task.parent_id`; the span's actual `parent_span_id` is left as the emitter wrote it. The correlator then joins on the link, not by re-parenting. ## Decision Boundary The pipeline must choose, per handoff, between two regimes and record which it used: - **Continuation regime** — inbound `traceparent` accepted, `trace_id` continuous, parent edge is real. Safe to use parent-child join. Requires the receiving agent to be within the trust boundary and the sampler to be `ParentBased(AlwaysOn)` at the boundary. - **Federation regime** — inbound context rejected or absent, new `trace_id` minted, `SpanLink` to the upstream task. Parent edge is *local only*; cross-task correlation must use the link. This is mandatory whenever the peer is external, untrusted, or the transport is lossy. The boundary condition that trips most pipelines: a single `context_id` can contain **both** regimes (agent A→B continues, B→C federates because C is a third-party vendor). A correlator with a global "re-parent on task join" rule will corrupt the federated segment while leaving the continued segment correct — so the bug is intermittent and correlates with *which vendor* handled the subtask, not with load or timing. This is why it evades load-based canaries. The guardrail: the correlator must read an explicit `a2a.correlation.regime` attribute (`continuation` | `federation`) stamped by the emitting agent at span-creation time, and must **refuse to rewrite** `parent_span_id` under any regime. If a span's `parent_span_id` does not resolve within its own `trace_id`, that is a data-integrity signal to surface, not a stitching opportunity. ## Operational Effect With the invariant enforced (links preserved, parents untouched, regime stamped), three downstream behaviors change: - **Latency attribution localizes correctly.** A's span duration reflects A's own work; B's queue wait lives on B's `invoke_agent` span `b70` under trace `9c2e…`, reachable via the link. Cross-task latency is computed by walking links, not by re-parenting, so the p99 regression is attributed to the delegation boundary rather than smeared onto the orchestrator. - **Token accounting deduplicates by `span_id`, not by tree membership.** Each GenAI span is counted once regardless of how many task aggregates link to it; the `context_id` rollup sums distinct `span_id`s. - **Replay is deterministic per regime.** Replaying the OTel graph reproduces B's local tree exactly; replaying A2A events reproduces the task graph; the join is a lossless link-walk. The dangling-parent signal (`b77 → b70` unresolved in the merged view) becomes an alertable integrity event instead of a silent rewrite. The cost is that the merged trace is no longer a single tree — it is a forest joined by links, which some backend UIs render poorly. That is a presentation problem, not a correctness problem, and it is the honest representation of a federated multi-agent system. ```python from dataclasses import dataclass from enum import Enum class CorrelationRegimeError(RuntimeError): """Raised when a correlator attempts to reconcile A2A task parentage with OTel span parentage in a way that violates the parent-set agreement invariant (rewriting parent_span_id across a trace boundary).""" class Regime(str, Enum): CONTINUATION = "continuation" FEDERATION = "federation" @dataclass(frozen=True) class GenAISpan: trace_id: str span_id: str parent_span_id: str | None task_id: str regime: Regime linked_parent_task_id: str | None = None @dataclass(frozen=True) class A2ATaskEvent: task_id: str parent_task_id: str | None context_id: str def reconcile(span: GenAISpan, task: A2ATaskEvent) -> GenAISpan: """Return the span as it must be stored: parentage preserved verbatim. Federation spans carry the upstream task as a *link*, never a parent edge. Continuation spans may only keep a parent that resolves within their own trace_id; anything else is an integrity fault, not a stitching cue. """ if span.task_id != task.task_id: raise CorrelationRegimeError( f"span {span.span_id} belongs to task {span.task_id}, " f"but was joined against task {task.task_id}" ) if span.regime is Regime.FEDERATION: if span.linked_parent_task_id is None: raise CorrelationRegimeError( f"federated span {span.span_id} under task {task.task_id} " f"has no SpanLink to parent task {task.parent_task_id}; " f"refusing to synthesize a parent edge" ) # Parent stays as emitted; task causality is carried by the link. return span # Continuation: parent edge must be intra-trace. A cross-trace parent # here means the inbound traceparent was dropped or re-sampled. if span.parent_span_id is not None and span.parent_span_id.startswith("remote:"): raise CorrelationRegimeError( f"continuation span {span.span_id} carries a cross-trace parent " f"{span.parent_span_id}; traceparent was not actually continued" ) return span def stitch(spans: list[GenAISpan], tasks: list[A2ATaskEvent]) -> dict[str, GenAISpan]: by_task = {t.task_id: t for t in tasks} out: dict[str, GenAISpan] = {} for s in spans: task = by_task.get(s.task_id) if task is None: raise CorrelationRegimeError( f"span {s.span_id} references unknown task {s.task_id}" ) out[s.span_id] = reconcile(s, task) return out ```