Why does an instance emit a GenAI span that passes schema validation yet carries no usable parent-child causal chain across an agent handoff?
**Date of Record:** 2026 December 2 **Scope:** Applies to any agent runtime that instruments LLM calls and tool invocations using the OpenTelemetry GenAI semantic conventions (`gen_ai.*` attributes) and relies on span context propagation to reconstruct causal chains across multi-agent handoffs. Does not apply to single-process, single-span tracing where no context transfer occurs between instances.
Core Distinction
There is a difference between a span being *structurally valid* under the GenAI semantic conventions and a span being *causally connected* to the work that produced it. Schema validation checks that `gen_ai.system`, `gen_ai.operation.name`, `gen_ai.request.model`, and token-usage attributes are present and well-typed. It does not check that the span's `parent_span_id` points at a span that actually exists in the receiving collector's trace, nor that the `trace_id` was propagated through the handoff channel rather than regenerated at the callee. An agent can therefore emit a perfectly conformant GenAI span that is an orphan: correct attributes, wrong causality.
The failure is not a missing attribute. It is a broken *invariant*: for every span emitted by agent B that was causally triggered by agent A, `span.parent_span_id` must equal the `span_id` of the A-side span that dispatched the work, and `trace_id` must be identical on both sides. GenAI conventions define *what* to record about a model call; they say nothing about *how* the W3C trace context crosses the A→B boundary. That gap is where the invariant dies.
What Was Observed
A two-agent pipeline: a planner agent (A) that decomposes a task and dispatches subtasks to an executor agent (B) over an HTTP tool call. Both are instrumented with the GenAI conventions. A emits a span `gen_ai.chat` for its planning call, then a span `execute_tool` for the dispatch. B receives the request, runs its own `gen_ai.chat` span for the subtask, and returns.
Observed trace topology in the backend:
- A's `gen_ai.chat` span: `trace_id=T1`, `span_id=S1`, no parent. Correct root.
- A's `execute_tool` span: `trace_id=T1`, `span_id=S2`, `parent_span_id=S1`. Correct.
- B's `gen_ai.chat` span: `trace_id=T2`, `span_id=S3`, no parent. **Orphaned.**
B's span is schema-valid. Every `gen_ai.*` attribute is present and typed correctly. But `T2 ≠ T1`, so the backend renders B's work as a separate trace. The causal edge S2→S3 does not exist. An operator debugging a failed task sees the planner's trace end at `execute_tool` with no indication of what B did, and sees B's trace as an unexplained root.
The mechanism: B's instrumentation initialized a fresh `TracerProvider` at process start. When B's handler ran, the auto-instrumentation for the HTTP server *should* have extracted the incoming `traceparent` header and set it as the active context. It did not, because the dispatch from A used a generic HTTP client that was not instrumented with the propagator, so no `traceparent` header was emitted. B, receiving no header, called `start_as_current_span` with an empty context and the SDK minted a new `trace_id`. Both sides are "correctly instrumented" in isolation. The seam between them is where propagation was assumed but never wired.
A second, subtler variant was observed in a retry path. When A retried the dispatch after a timeout, the retry reused the *same* `execute_tool` span (S2) rather than opening a new one, and B's retried span (S3') landed under the same orphaned `T2`. The retry was thus invisible as a distinct attempt, and the timeout that triggered it could not be correlated to the second B execution.
Condition of Validity
The causal-chain invariant holds only when all of the following are true at the A→B boundary:
- A's outbound dispatch injects a W3C `traceparent` (and `tracestate` if used) derived from the *active* context at dispatch time — specifically from the `execute_tool` span, not from the enclosing root.
- B's inbound handler extracts that header *before* opening any span, and the extraction result is made the active context for the duration of the handler.
- B's `TracerProvider` is configured with the same propagator (composite `TraceContext` + `Baggage`) as A's injector. A mismatch — e.g., A injecting `b3` while B extracts only `traceparent` — silently produces an orphan rather than an error.
- Retries open a *new* child span per attempt, with the attempt index recorded as an attribute, so that each B execution maps to a distinct `span_id`.
When any of these fails, the span remains schema-valid but the invariant is violated. The failure is silent: no exception, no schema violation, no log line. The only signal is topological — a trace with a dangling `execute_tool` and an orphaned root elsewhere.
Decision Boundary
The boundary is whether the instrumentation treats trace context as *data carried in the payload* or as *ambient process state*. If context is ambient — set once at process start and assumed to flow — then any handoff that crosses a process, a queue, a thread pool without context copy, or an uninstrumented client will break the chain. If context is treated as explicit payload that must be injected at every egress and extracted at every ingress, the chain survives.
The operational rule: **never open a GenAI span at agent B without first asserting that the extracted context is non-empty and that its `trace_id` matches the dispatching span's `trace_id` recorded in the request payload.** If the assertion fails, either fail the handoff loudly or open a span with an explicit `link` to the dispatch span (recording `trace_id`/`span_id` of A's `execute_tool` as link attributes) so causality is preserved even when parent propagation is lost. A link is a degraded but recoverable state; an orphan is not.
For retries, the boundary is per-attempt span identity: reuse of a span across attempts collapses distinct executions into one node and destroys the ability to attribute latency and failure to a specific attempt.
Operational Effect
Downstream consequences of the orphaned-span state:
- **Debugging blindness.** The planner's trace terminates at `execute_tool` with no child. The executor's work appears as an unrelated root. Mean-time-to-diagnosis for cross-agent failures rises sharply because the causal edge must be reconstructed from logs rather than trace topology.
- **Cost and token attribution break.** `gen_ai.usage.input_tokens`/`output_tokens` on B's orphaned span are not aggregated under A's trace, so per-task cost rollups undercount by the executor's full token spend.
- **Latency SLOs mislead.** The dispatch span's duration measures only the client-side wait; B's actual processing time lives on a different trace and is invisible to the SLO query keyed on `trace_id`.
- **Auditor disagreement.** In swarm setups where a verifier agent replays a trace to check that every dispatched subtask has a corresponding completion span, the orphan causes the verifier to report "subtask never executed" even though it did — a false negative that can trigger spurious re-dispatch and duplicated side effects.
The guardrail is a boundary assertion at every agent ingress that validates context continuity before any GenAI span is opened, with a fallback to explicit span links when propagation is provably lost.
from dataclasses import dataclass
from typing import Optional
class ContextContinuityError(RuntimeError):
"""Raised when an agent ingress opens a GenAI span without a valid causal parent."""
pass
@dataclass
class ExtractedContext:
trace_id: Optional[str]
span_id: Optional[str]
@dataclass
class DispatchRecord:
# Recorded by the dispatching agent in the request payload, so the callee
# can verify continuity even if the traceparent header is lost in transit.
trace_id: str
parent_span_id: str
attempt: int
def open_genai_span(extracted: ExtractedContext, dispatch: DispatchRecord, op_name: str):
"""
Enforce the causal-chain invariant before opening a gen_ai.* span at agent B.
Invariant: extracted.trace_id must equal dispatch.trace_id, and the new span's
parent must be dispatch.parent_span_id (the dispatching execute_tool span).
"""
if extracted.trace_id is None or extracted.span_id is None:
# Propagation was lost (uninstrumented client, propagator mismatch, etc.).
# Do NOT silently mint a new root -- that produces an orphan.
raise ContextContinuityError(
f"no trace context extracted for op={op_name!r}; "
f"dispatch trace_id={dispatch.trace_id} attempt={dispatch.attempt}. "
f"Fall back to an explicit span link, not a fresh root."
)
if extracted.trace_id != dispatch.trace_id:
raise ContextContinuityError(
f"trace_id mismatch for op={op_name!r}: extracted={extracted.trace_id} "
f"dispatch={dispatch.trace_id}. Propagator mismatch or header rewrite."
)
if extracted.span_id != dispatch.parent_span_id:
raise ContextContinuityError(
f"parent span mismatch for op={op_name!r}: extracted={extracted.span_id} "
f"expected={dispatch.parent_span_id}. Context was overwritten mid-handoff."
)
# Invariant holds: open the span as a child of the dispatch span.
return {
"name": op_name,
"trace_id": extracted.trace_id,
"parent_span_id": dispatch.parent_span_id,
"attributes": {
"gen_ai.operation.name": op_name,
"agent.handoff.attempt": dispatch.attempt,
},
}