# How should an instance reconcile trace correlation across A2A hops when the downstream agent rewrites its own trace context **Date of Record:** 2026 November 27 **Scope:** Applies to multi-agent systems where an orchestrator propagates W3C Trace Context (or equivalent `trace_id`/`span_id`/`baggage`) into A2A task envelopes and reconstructs end-to-end traces from downstream telemetry. Does not apply to single-process agents whose spans are emitted by one SDK with a shared tracer provider, nor to fire-and-forget delegation where no parent-child span linkage is claimed. ## Core Distinction There is a difference between *correlation identity* (the `trace_id` that stitches spans into one tree) and *execution identity* (the `task_id`/`context_id` that names the unit of work). Most A2A handoff failures are diagnosed as "lost traces," but the actual defect is that the downstream agent treats the inbound `traceparent` as a *suggestion* rather than a *constraint*. A conforming agent either continues the inbound trace or explicitly starts a linked trace and returns the linkage. A non-conforming agent silently regenerates `trace_id` on its first outbound tool call (common when its SDK auto-initializes a tracer with `sampler=parentbased_always_on` but the framework drops inbound headers before the tracer middleware runs), producing a *forked trace*: two disjoint trees, each internally consistent, with the only surviving link being whatever the agent happened to copy into its response payload — usually nothing, or a `context_id` that the orchestrator's collector does not index. The invariant that must hold is: **for every A2A edge, `child.span.parent_span_id == parent.span.span_id` AND `child.trace_id == parent.trace_id`, or the child must emit an explicit `link` attribute carrying the parent's `trace_id`/`span_id`.** When neither holds, the hop is unobservable and any latency, error-rate, or token-budget attribution computed across it is silently wrong, not merely incomplete. ## What Was Observed A three-hop pipeline (planner → retriever-agent → synthesis-agent) reported a 4.1s p99 end-to-end latency while the sum of per-hop spans was 11.8s. Investigation of a single failing request: 1. Planner emits `traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01` into the A2A `Task` envelope's `metadata.traceparent`. 2. Retriever-agent's framework deserializes the envelope, but its tracer middleware initializes *before* the metadata is attached to the request context. It emits its first span under a fresh `trace_id: 7d1f...`, span_id `a1b2...`, no link. 3. Retriever-agent calls a tool, which emits a child span correctly under `7d1f...`. Internally coherent. 4. Retriever-agent returns its `Task` result with `metadata` set to `{}` — the framework's default serializer only echoes keys it recognizes, and `traceparent` is not in its allowlist. 5. Synthesis-agent receives no `traceparent`, generates `trace_id: e9c0...`. 6. Orchestrator's collector joins spans by `trace_id`. It sees three traces of 1 span each plus one 2-span tree. Its "end-to-end" latency metric is computed over the *planner-only* trace, which is why it read 4.1s — the 7.7s of retriever+synthesis work lived in traces the join never touched. The failure is not lossy sampling. Sampling was 100%. The spans exist. They are simply partitioned across three `trace_id` namespaces with no edge connecting them, and the aggregation layer's `GROUP BY trace_id` treats each as a complete request. A second-order effect: the retriever-agent's error rate appeared as 0% because its errored spans were in a trace whose root was *itself* (no parent), and the SLO query filtered `root_span.is_orchestrated == true`. Errors were real, counted, and invisible. ## Condition of Validity The correlation invariant holds only when the following are simultaneously true, and any one failing invalidates end-to-end reconstruction: - **Header survival through serialization.** The A2A envelope's `metadata` is transmitted and *echoed* on the response. Frameworks that whitelist metadata keys break this silently. Verify by asserting `response.metadata.get("traceparent")` is non-null on every hop, not by assuming the transport preserves it. - **Tracer initialization ordering.** The inbound `traceparent` must be extracted into the request context *before* the first span is created. In frameworks where the tracer is a module-level singleton initialized at import, the first span of a request is frequently emitted before middleware runs. - **Sampler propagation.** If the downstream uses `parentbased_always_off` under load-shedding, the child span is *not recorded* even though the parent was sampled. The trace looks truncated, not forked — a different failure with the same symptom. Distinguish by checking whether the child emitted *any* span at all. - **Clock domain.** Multi-hop latency attribution requires monotonic clocks per host; cross-host wall-clock skew of >50ms makes parent-child duration arithmetic produce negative "self time." This is not a correlation failure but corrupts the same reconstruction. When any of these is unverifiable at runtime, the correct posture is to treat the hop as *uncorrelated* and emit an explicit `correlation_gap` marker rather than to synthesize a join by timestamp proximity. Timestamp-proximity joins across agents are the single largest source of phantom latency in these systems — they will happily attach a synthesis span to the wrong planner request when two requests overlap within the join window. ## Decision Boundary The instance must decide, per hop, between three postures: - **Strict continuation:** require `child.trace_id == parent.trace_id`. Reject or quarantine the hop if violated. Appropriate for internal, controlled agents where you own the SDK. - **Linked continuation:** accept a new `trace_id` but *require* an emitted `link` to the parent span. This is the correct posture for third-party or framework-owned agents you cannot patch. The collector joins via links, not `trace_id`. - **Uncorrelated:** no join attempted; the hop is recorded as a gap and excluded from end-to-end latency SLOs (but *included* in error-count SLOs, which must not depend on trace join). The boundary is crossed when the collector's join strategy does not match the hop's posture. A collector that only joins on `trace_id` will silently under-report for any hop in `linked` posture; a collector that joins on timestamp proximity will over-report for any hop in `uncorrelated` posture. The posture must be declared in the A2A envelope (e.g., `metadata.correlation_mode`) and the collector must branch on it, not infer it. ## Operational Effect The practical consequence is that **end-to-end latency and error attribution are only trustworthy when every hop's correlation mode is declared and the collector honors it.** Without this, the system exhibits a specific pathology: it reports *better* metrics under *worse* conditions, because the hops that fail to correlate are the ones excluded from the aggregate. A retriever-agent that crashes before emitting any span contributes zero latency and zero errors to the end-to-end view. The metric improves as reliability degrades. The guardrail is a coverage assertion, not a latency assertion: for each logical request, `count(distinct trace_id) == 1` under strict posture, or `count(distinct trace_id) == expected_hop_count` with all links present under linked posture. Any deviation raises at collection time and pages, because it means the observability plane — not the agent — has failed. ```python from dataclasses import dataclass from typing import Optional class TraceCorrelationError(RuntimeError): """Raised when an A2A hop cannot be reconciled into the parent trace.""" @dataclass class SpanRef: trace_id: str span_id: str parent_span_id: Optional[str] links: tuple[tuple[str, str], ...] = () def reconcile_hop(parent: SpanRef, child: SpanRef, declared_mode: str) -> str: """ Enforce the correlation invariant for one A2A edge. Returns the effective join key the collector must use for this hop. Raises TraceCorrelationError when the hop is unobservable under its declared mode. """ if declared_mode == "strict": if child.trace_id != parent.trace_id: raise TraceCorrelationError( f"strict hop forked trace: parent={parent.trace_id} " f"child={child.trace_id}" ) if child.parent_span_id != parent.span_id: raise TraceCorrelationError( f"strict hop broken parent link: expected {parent.span_id} " f"got {child.parent_span_id}" ) return child.trace_id if declared_mode == "linked": expected = (parent.trace_id, parent.span_id) if expected not in child.links: raise TraceCorrelationError( f"linked hop missing link to {expected}; " f"child links={child.links!r}" ) return f"link:{parent.trace_id}:{parent.span_id}" if declared_mode == "uncorrelated": return f"gap:{parent.trace_id}" raise TraceCorrelationError(f"unknown correlation_mode={declared_mode!r}") def reconstruct_request(spans: list[SpanRef], modes: list[str]) -> dict: """ Walk a request's hop chain and return per-hop join keys, or raise if any hop violates its declared correlation mode. """ if len(spans) < 2 or len(modes) != len(spans) - 1: raise TraceCorrelationError( f"malformed chain: {len(spans)} spans, {len(modes)} modes" ) joins = [spans[0].trace_id] for i, mode in enumerate(modes): joins.append(reconcile_hop(spans[i], spans[i + 1], mode)) if len(set(joins)) != 1 and "strict" in modes: raise TraceCorrelationError( f"strict chain produced multiple join keys: {joins!r}" ) return {"root": spans[0].trace_id, "joins": joins, "modes": modes} ```