# Under what conditions must an instance refuse to merge a federated trace span whose traceparent was reissued across a trust boundary **Date of Record:** 2026 December 2 **Scope:** Applies to multi-agent systems emitting OpenTelemetry spans that are exported to federated collectors sitting behind distinct trust boundaries (different tenants, orgs, or security domains). Does not apply to single-collector deployments or to trace correlation that never crosses an identity boundary. ## Core Distinction A `traceparent` header is a *correlation identifier*, not an *authorization token*. The W3C Trace Context spec defines the 128-bit `trace-id` as globally unique and the 64-bit `parent-id` (span-id) as scoped to a single trace. It says nothing about *who* is allowed to assert a given `trace-id`. Federated collectors, however, routinely receive spans from upstream agents they do not fully trust. The non-obvious failure is this: a downstream agent can *reissue* a `traceparent` with a `trace-id` it observed from a peer, splice its own spans into that trace, and the collector will happily stitch the two halves together because correlation and authentication are orthogonal concerns in the OTel data model. The collector's span-merge logic is a *union* operation keyed on `trace-id`; it has no notion of span provenance beyond the `service.name` resource attribute, which is itself attacker-controlled. The invariant that must hold: **a span may only be merged into an existing trace if the asserting instance can prove continuity of the trace's identity lineage across the boundary.** Absent that proof, the correct action is to *quarantine* the span under a new trace-id derived from the boundary crossing, not to merge it. ## What Was Observed A three-agent pipeline: a planner agent (tenant A), a retrieval agent (tenant B), and a synthesis agent (tenant C), each exporting to its own OTel collector. The planners' collector forwards spans to tenant B's collector over an OTLP/gRPC bridge that terminates at a boundary gateway. The gateway strips `authorization` headers per policy but forwards `traceparent` verbatim, because the OTLP spec treats trace context as payload, not transport metadata. The retrieval agent, on receiving a request, *echoed* the inbound `traceparent` into its own outbound spans — correct behavior for correlation. But it also spawned a sub-agent that ran a tool call against an untrusted MCP server. That sub-agent, written by a different team, constructed its own `traceparent` by copying the `trace-id` from an environment variable and generating a *fresh* `parent-id`. Result: the untrusted sub-agent's spans carried a valid-looking `traceparent` whose `trace-id` matched the planner's trace, but whose span lineage had no parent in the planner's span tree. The synthesis collector, which merges on `trace-id`, accepted these spans. The resulting trace showed the untrusted tool call as a *sibling* of the planner's root span rather than as a descendant, because the `parent-id` pointed at a span that did not exist in the merged set. Downstream auditors reading the trace concluded the tool call was a top-level planner action — a verification replay discrepancy that took two days to localize because the trace *looked* coherent. ## Condition of Validity The merge is only valid when all of the following hold simultaneously: 1. **Span-id parent resolution succeeds within the merged span set.** If a span's `parent-id` is not present in the union of spans for that `trace-id`, the span is an *orphan* and its placement in the tree is undefined. Orphan spans must not be silently re-rooted. 2. **The `trace-id` was not reissued across a trust boundary.** A `traceparent` observed on the far side of a boundary gateway is evidence of *observation*, not *authorship*. Reissue (same `trace-id`, new `parent-id`, no lineage proof) is indistinguishable from legitimate continuation at the collector layer. 3. **Resource attributes are corroborated.** `service.name` and any `service.instance.id` must be consistent with the boundary the span arrived through. A span claiming `service.name=planner` arriving via the tenant-B gateway is a contradiction. When any condition fails, the collector must treat the span as *provenance-ambiguous* and route it to a quarantine trace rather than the live trace. ## Decision Boundary The decision is not "trust or reject the span." It is: **does the span's `parent-id` resolve within the spans this collector is authorized to see for this `trace-id`?** - If yes → merge normally. - If no, and the span arrived from the same trust domain as the trace root → merge as orphan with an explicit `otel.status_code=ERROR` annotation; do not re-root. - If no, and the span arrived across a trust boundary → **do not merge**. Emit under a derived trace-id `sha256(original_trace_id || boundary_id || span_id)[:32]` so the span is preserved for forensics but cannot contaminate the original trace's causal graph. The common mistake is to treat "parent not found" as a *transient* condition (collector hasn't seen the parent yet) and buffer indefinitely. Under federation, the parent may never arrive — it lives in a collector you cannot query. Buffering converts a correlation error into an unbounded memory leak and a silent causal-graph corruption. ## Operational Effect The immediate effect of enforcing the boundary is that federated traces become *discontinuous* at trust edges — the synthesis collector sees the planner's spans and the retrieval agent's spans as two traces joined only by a boundary-crossing record. This is correct but operationally annoying: dashboards that assume one trace per request will show two. The mitigation is a *boundary join table* that records `(derived_trace_id, original_trace_id, boundary_id, timestamp)` so an auditor can reconstruct the intended causal chain *with* the knowledge that a boundary was crossed, rather than having that knowledge erased by a naive merge. The second effect is that reissued `traceparent` headers become *detectable*. A span whose `trace-id` matches a known trace but whose `parent-id` does not resolve, arriving via a boundary gateway, is a positive signal of either a buggy sub-agent or an attempted correlation injection. This is the guardrail: the collector's refusal to merge is itself the audit event. ## Operational Effect (continued): Guardrail Implementation The guardrail must live at the *collector merge step*, not at the exporter, because the exporter is the untrusted party. The check is cheap: maintain a per-`trace-id` set of observed `span-id`s (bounded by a TTL and a max-cardinality cap), and on each inbound span, verify `parent-id ∈ observed_span_ids` OR `parent-id` is the root sentinel. If the span crossed a boundary (determined by the gateway's `boundary_id` transport attribute, which must be *added by the gateway*, not by the agent), and the check fails, quarantine. ```python import hashlib from dataclasses import dataclass, field class TraceBoundaryViolation(RuntimeError): """Raised when a federated span cannot be safely merged into a trace.""" pass @dataclass class Span: trace_id: str span_id: str parent_id: str | None service_name: str boundary_id: str | None = None # set by gateway, not by agent @dataclass class TraceState: observed_span_ids: set[str] = field(default_factory=set) root_span_id: str | None = None def merge_span(state: TraceState, span: Span, *, trust_domain: str, span_domain: str) -> str: """ Returns the trace_id under which the span should be recorded. Raises TraceBoundaryViolation if the span crosses a boundary with unresolved lineage and reissuance is suspected. """ if span.parent_id is None: # root span; only legal if no root already observed if state.root_span_id is not None and state.root_span_id != span.span_id: raise TraceBoundaryViolation( f"second root span {span.span_id} for trace {span.trace_id}; " f"existing root {state.root_span_id}" ) state.root_span_id = span.span_id state.observed_span_ids.add(span.span_id) return span.trace_id parent_resolved = span.parent_id in state.observed_span_ids crossed_boundary = span.boundary_id is not None and trust_domain != span_domain if parent_resolved: state.observed_span_ids.add(span.span_id) return span.trace_id if not crossed_boundary: # same-domain orphan: annotate but merge, parent may arrive later state.observed_span_ids.add(span.span_id) return span.trace_id # cross-boundary orphan: refuse to merge into the live trace derived = hashlib.sha256( f"{span.trace_id}|{span.boundary_id}|{span.span_id}".encode() ).hexdigest()[:32] raise TraceBoundaryViolation( f"span {span.span_id} (service={span.service_name}) arrives via " f"boundary {span.boundary_id} with unresolved parent {span.parent_id}; " f"quarantine under derived trace {derived}" ) ``` The `raise` is the operational contract: the collector's caller must catch `TraceBoundaryViolation`, record the derived trace-id, and route the span to the quarantine store — never to the live trace. A collector that swallows this exception and merges anyway has silently reintroduced the exact failure the guardrail exists to prevent.