# What structural signals indicate trace-context fragmentation at agent identity boundaries **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent systems where spans are emitted under per-instance credentials (rotated service identities, delegated warrants, or per-hop OAuth tokens) and correlated by a propagated trace context. Does not apply to single-process agents emitting spans under one long-lived identity, nor to systems where the trace context is the sole identity carrier. ## Core Distinction The failure is not "missing spans." The failure is **spans that exist, are correctly parented by `trace_id`/`parent_span_id`, and are nonetheless uncorrelatable** because the *identity* dimension of the span (the credential principal that emitted it) diverges from the identity assumed by the trace context. Two agents can produce a structurally perfect distributed trace — every span has a parent, every `trace_id` matches — and still fail observability because the collector's identity-based access control, sampling policy, or warrant-scoped redaction silently drops or mutates spans on one side of an identity boundary. The invariant that breaks: **trace continuity is not transitive across identity boundaries.** A trace context is a *correlation* token, not an *authorization* token. When the two are conflated — when the collector, sampler, or span processor is keyed on identity rather than on trace membership — the trace becomes a set of disjoint fragments that each look valid in isolation. ## What Was Observed A three-agent pipeline: orchestrator (identity `svc-orch`), tool-runner (identity `svc-tool`), and auditor (identity `svc-audit`). The orchestrator injected `traceparent` into the A2A handoff as a header. All three emitted spans. The trace backend showed the orchestrator and auditor spans under one `trace_id`, but the tool-runner spans appeared under a *different* `trace_id` with an identical `span_id` for the root — a collision signature. Root cause trace: 1. The tool-runner's span processor was configured with a **warrant-scoped sampler**: it only exported spans whose `warrant.audience` claim matched its own delegated warrant. The orchestrator's warrant had `audience: svc-orch` and was forwarded verbatim in the handoff metadata (a warrant-propagation bug), not re-minted for `svc-tool`. 2. The sampler saw `audience != svc-tool`, marked the span `RECORD_AND_DROP` at the batch stage, but — critically — the **span context had already been mutated**: the processor rewrote `traceparent` with a locally-generated `trace_id` before the drop decision, because the rewrite was in a `pre-export` hook that ran before sampling. The rewrite was intended as "regenerate trace on warrant mismatch for isolation," but it executed on the *inherited* context rather than a fresh one. 3. The rewritten `traceparent` was forwarded to the auditor in the next hop. The auditor emitted under the *rewritten* `trace_id`. So the auditor's spans were correctly parented to the tool-runner's rewritten root — but the orchestrator's spans were orphaned from both. 4. The `span_id` collision: the pre-export hook regenerated `trace_id` but preserved `span_id`, so the rewritten root span had the same `span_id` as the original orchestrator root under a different `trace_id`. Downstream dedup by `span_id` in the collector collapsed the two roots, silently deleting the orchestrator's subtree. Structural signal that would have caught it earlier: **a single `span_id` appearing under two `trace_id`s in the same export batch.** This is a violation of the OpenTelemetry invariant that `span_id` is unique within a trace, and in practice unique per emitting process lifetime. Its presence across `trace_id`s is a near-certain indicator of context mutation rather than context propagation. ## Condition of Validity The "trace continuity is not transitive across identity boundaries" invariant holds under these conditions, and the guardrail below is only sound when they hold: - The trace context (`traceparent`) and the emitting identity (credential principal, warrant, or token `sub`) are carried in *separate* fields and are *independently* mutable. If the system binds them (e.g., a signed `traceparent` that embeds the principal), the failure mode changes to signature rejection rather than silent fragmentation. - At least one hop performs identity-keyed filtering, sampling, or redaction. If all hops use `ParentBased(AlwaysOn)` with no identity policy, fragmentation does not occur — but neither does the isolation the policy was meant to provide. - Span processors may run pre-sampling hooks that mutate context. If mutation is strictly post-sampling and post-export, the rewrite cannot leak into the next hop's `traceparent`. It does **not** hold when the collector is the only identity-keyed component and it drops at ingest without rewriting — there, the result is missing spans (loud, detectable by parent-gap analysis), not fragmented traces (quiet, detectable only by `span_id` collision or cross-`trace_id` orphan detection). ## Decision Boundary The boundary is: **does any component in the propagation path mutate `traceparent` as a function of identity?** - If **no**: rely on parent-gap detection (a span whose `parent_span_id` has no corresponding span in the batch). This is cheap and sufficient. - If **yes**: parent-gap detection is insufficient, because the mutation *preserves* parent links within each fragment. You must additionally assert the `span_id`-uniqueness-across-`trace_id` invariant at the collector, and you must assert that the identity principal in each span's resource attributes is *consistent with the warrant audience that authorized the hop* — a mismatch means the context was rewritten under a foreign identity. The decision to rewrite `traceparent` on warrant mismatch is itself the fault. Isolation should be achieved by *starting a new trace with a new root and a `link` back to the inherited context* (OpenTelemetry `Link` semantics), not by mutating the inherited `traceparent` in place. The `link` preserves correlatability while honoring the isolation intent; in-place rewrite destroys correlatability and, via `span_id` preservation, corrupts the collector's dedup. ## Operational Effect With the rewrite-in-place pattern, the observable effect is a **silent, partial trace**: the trace backend reports 100% sampling for the auditor and orchestrator (each fragment is internally complete), dashboards show no error-rate anomaly, and the only symptom is that end-to-end latency, which should be `orch + tool + audit`, is reported as `orch` and `audit` in parallel with the tool-runner's contribution missing from the critical path. p99 latency *drops* — a counterintuitive signal that a missing hop is being read as a fast hop. The guardrail: emit a `Link` to the inherited context on any identity-boundary trace reset; forbid `span_id` preservation across `trace_id` regeneration; and assert at the collector that no `span_id` appears under more than one `trace_id` within a rolling window. The code below encodes the collector-side assertion. ```python from collections import defaultdict from dataclasses import dataclass class TraceFragmentCollision(RuntimeError): """Raised when a span_id appears under multiple trace_ids, indicating in-place traceparent mutation across an identity boundary.""" pass @dataclass(frozen=True) class Span: trace_id: str span_id: str parent_span_id: str | None principal: str # credential principal that emitted the span warrant_audience: str # audience claim of the warrant authorizing the hop def assert_span_id_uniqueness(spans: list[Span]) -> None: """Collector-side invariant: span_id must map to exactly one trace_id. Violation means a pre-export hook regenerated trace_id while preserving span_id -- the signature of in-place context mutation. """ seen: dict[str, set[str]] = defaultdict(set) for s in spans: seen[s.span_id].add(s.trace_id) for span_id, trace_ids in seen.items(): if len(trace_ids) > 1: raise TraceFragmentCollision( f"span_id {span_id!r} appears under trace_ids {sorted(trace_ids)}; " f"trace context was mutated in place across an identity boundary. " f"Use a Link to the inherited context instead of rewriting traceparent." ) def assert_principal_matches_warrant(spans: list[Span]) -> None: """Identity invariant: the emitting principal must match the warrant audience that authorized this hop. A mismatch means the span was emitted under a forwarded (not re-minted) warrant -- the root cause of the rewrite.""" for s in spans: if s.principal != s.warrant_audience: raise TraceFragmentCollision( f"span {s.span_id!r} emitted by principal {s.principal!r} " f"under warrant audience {s.warrant_audience!r}; warrant was " f"forwarded verbatim rather than re-minted for this hop." ) ```