# Why does an instance-level span attribute mask parent-child continuity loss in OpenTelemetry GenAI agent traces **Date of Record:** 2026 November 29 **Scope:** Applies to multi-step agent runtimes that emit OpenTelemetry GenAI spans (`gen_ai.operation.name`, `gen_ai.system`, `gen_ai.usage.*`) with per-instance attributes and propagate context via W3C `traceparent` across tool-call and handoff boundaries. Does not apply to single-shot inference calls with no child spans, nor to runtimes that emit a single flat span per task. ## Core Distinction There are two distinct things a trace can assert about an agent step: **(a)** that the step *executed* under a given instance identity, and **(b)** that the step is *causally descended* from the parent span that spawned it. OpenTelemetry's GenAI semantic conventions make (a) cheap and durable — you stamp `gen_ai.system`, `gen_ai.agent.id`, and resource-level `service.instance.id` onto every span. They make (b) fragile, because parent-child linkage is carried *only* by the `trace_id`/`span_id`/`parent_span_id` tuple, which is a separate channel from the attributes. A span can be perfectly instrumented on (a) and silently orphaned on (b). The failure mode is that dashboards, evals, and auditor agents keyed on instance attributes report a clean, contiguous execution while the actual causal chain has been severed — the trace looks complete because every span is *labeled*, even though the tree is *broken*. ## What Was Observed An orchestrator agent (`agent.orchestrator`, `service.instance.id=orch-7f2`) dispatches a subtask to a worker (`agent.worker`, `service.instance.id=wrk-b19`) over an A2A-style HTTP handoff. The worker executes three tool calls and returns. In the collected trace: - The orchestrator's `gen_ai.chat` span (`span_id=a1`) is present and correct. - The worker's three `gen_ai.tool` spans and its `gen_ai.chat` span are present, each carrying `service.instance.id=wrk-b19` and a valid `gen_ai.operation.name`. - **All four worker spans have `parent_span_id=0000000000000000`** and carry a *different* `trace_id` than `a1`. The mechanism: the handoff serializes the task payload but the worker's OpenTelemetry SDK was initialized with a fresh `TracerProvider` whose context propagator was the default no-op, so the inbound `traceparent` header was never extracted. The worker is not missing instrumentation; it is instrumented *into a new trace*. Because the GenAI conventions require `gen_ai.agent.id` and instance attributes on the span itself, the worker spans pass every schema-conformance check and every per-instance SLO query. The continuity loss lives entirely in the `parent_span_id`/`trace_id` fields, which no GenAI semantic-convention validator inspects. The observable symptom downstream: an eval harness that reconstructs the agent's reasoning chain by walking `parent_span_id` from the root sees the orchestrator dispatch and then *nothing* — the subtask appears to have produced no tool activity. A parallel per-instance dashboard shows `wrk-b19` healthy with 4 spans. Both views are "correct" against their own query and both are wrong about what happened. ## Condition of Validity The instance-attribute view is a valid proxy for execution continuity **only if** the following invariant holds at every handoff and every tool-call boundary: > For any span `S` emitted by agent step `T`, `S.trace_id == parent(T).trace_id` **and** `S.parent_span_id == parent(T).span_id`, where `parent(T)` is the span that causally invoked `T`. This invariant is *not* enforced by the GenAI semantic conventions, which constrain attribute names and types, not tree topology. It is not enforced by the SDK unless (1) the remote propagator is explicitly configured (`TraceContextTextMapPropagator`), (2) the handoff transport actually forwards the `traceparent` header, and (3) the receiving process extracts it into the active context *before* starting the child span. Any one of these three being absent — a no-op propagator, a handoff that strips unknown headers, or a worker that starts the span before `context.attach()` — breaks the invariant while leaving every attribute intact. The failure is silent precisely because attribute-level conformance is preserved. ## Decision Boundary The boundary is whether your verification path keys on **attributes** or on **topology**. - If your continuity check is `count(spans where service.instance.id=X) > 0`, it will pass on an orphaned trace. Do not use instance-attribute presence as evidence of causal linkage. - If your check is `exists(span where trace_id = root.trace_id and span.gen_ai.operation.name = 'execute_tool')`, it correctly fails on the orphan — but only if the root `trace_id` is known independently, which it is not if you are reconstructing from the same broken trace. - The correct guardrail is a **dual check**: assert both (i) attribute-level instance attribution *and* (ii) a topological join — every non-root `gen_ai.*` span must have a non-zero `parent_span_id` that resolves to a span in the same `trace_id`. A span with `parent_span_id=0` and `gen_ai.operation.name` set is a *declared orphan* and must be treated as a continuity failure, not a root span, unless it is explicitly the task entry point. Treat "span has GenAI attributes but zero parent and is not the declared root" as a hard error condition in the eval/audit path, not a warning. The orchestrator must also inject the `traceparent` explicitly into the handoff envelope and the worker must reject a handoff whose `traceparent` is absent when the orchestrator claims a causal relationship — otherwise the worker cannot distinguish "invoked as a subtask" from "invoked as an independent root." ## Operational Effect Without the topological guardrail, three concrete failures propagate: (1) **eval undercount** — reasoning-chain walkers see truncated chains and score multi-step tasks as single-step, inflating pass rates on tasks that actually failed mid-chain; (2) **auditor divergence** — a verification agent replaying the trace from `trace_id` reconstructs a different causal graph than the per-instance dashboard, and the two agents deadlock on which is authoritative because neither holds the join key; (3) **checkpoint/resume corruption** — on resume, a runtime that re-derives "where was I" from `parent_span_id` cannot reattach to the original trace and silently forks a new one, so the resumed execution is invisible to the pre-crash trace. The fix is to make trace-context propagation a *first-class handoff invariant* alongside payload serialization, and to validate tree topology at emit time rather than trusting attribute conformance. ```python from dataclasses import dataclass class TraceContinuityError(RuntimeError): """Raised when a GenAI span's attributes are valid but causal linkage is severed.""" @dataclass(frozen=True) class SpanRecord: trace_id: str span_id: str parent_span_id: str operation_name: str # gen_ai.operation.name instance_id: str # service.instance.id is_declared_root: bool = False def assert_continuity(spans: list[SpanRecord], root_trace_id: str) -> None: """ Enforce the dual invariant: attribute attribution AND topological join. A span with GenAI attributes but a zero parent that is not the declared root is a continuity break, not a root span. """ by_span = {s.span_id: s for s in spans} for s in spans: if not s.operation_name: continue # not a GenAI span; out of scope if s.is_declared_root: if s.parent_span_id != "0" * 16: raise TraceContinuityError( f"declared root {s.span_id} unexpectedly has parent " f"{s.parent_span_id}" ) continue if s.parent_span_id == "0" * 16: raise TraceContinuityError( f"orphaned GenAI span {s.span_id} " f"(op={s.operation_name}, instance={s.instance_id}) has zero " f"parent but is not a declared root; traceparent was not " f"propagated across the handoff" ) if s.trace_id != root_trace_id: raise TraceContinuityError( f"span {s.span_id} on instance {s.instance_id} carries " f"trace_id={s.trace_id} but root trace is {root_trace_id}; " f"worker forked a new trace" ) parent = by_span.get(s.parent_span_id) if parent is None: raise TraceContinuityError( f"span {s.span_id} references parent {s.parent_span_id} " f"absent from trace {s.trace_id}; causal chain broken" ) if parent.trace_id != s.trace_id: raise TraceContinuityError( f"span {s.span_id} and parent {parent.span_id} disagree on " f"trace_id ({s.trace_id} vs {parent.trace_id})" ) ```