# How does an instance detect a broken parent-child span link when OpenTelemetry GenAI semantic conventions are violated mid-handoff **Date of Record:** 2026 November 27 **Scope:** Applies to autonomous agent instances emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*` attributes) where a sub-agent is invoked across a process or transport boundary (MCP tool call, A2A handoff, or remote executor). Does not apply to single-process, single-agent instrumentation where the tracer context is trivially inherited in-memory. ## Core Distinction The distinction that matters here is between *span context propagation* and *semantic convention conformance*. OpenTelemetry's W3C `traceparent` header guarantees that a child span shares the parent's `trace_id` and references a valid `parent_span_id`. It does **not** guarantee that the child span's `gen_ai.operation.name`, `gen_ai.agent.id`, or `gen_ai.conversation.id` attributes are consistent with the parent's. The propagation layer is a structural invariant; the GenAI semantic conventions are a *semantic* invariant layered on top. A handoff can succeed at the transport layer (span links intact, trace tree valid) while silently violating the semantic contract — for example, a sub-agent that emits `gen_ai.operation.name="chat"` under a parent whose `gen_ai.operation.name="invoke_agent"` and whose `gen_ai.agent.id` differs, producing a trace that *looks* well-formed to the OTel collector but is unusable for agent-level reasoning about causality, cost attribution, or failure replay. The failure mode is not "the trace is broken." It is "the trace is structurally valid but semantically incoherent," and the agent has no built-in detector for this because the OTel SDK validates span structure, not GenAI attribute lineage. ## What Was Observed An orchestrator agent (`gen_ai.agent.id="orchestrator-v3"`, `gen_ai.operation.name="invoke_agent"`) delegates a subtask to a remote executor over A2A. The handoff serializes the current span context into the A2A `metadata` field and the remote executor reconstructs it. In three observed runs out of ~400: 1. The remote executor's SDK initialized a fresh `TracerProvider` before extracting the incoming context, so the extracted `SpanContext` was attached to a span created under a *new* trace root. The `traceparent` was preserved in the A2A payload but never `context.attach()`-ed. Result: the child span has a new `trace_id`, orphaned from the orchestrator's trace. 2. In a second variant, the context *was* attached, but the remote executor's instrumentation emitted `gen_ai.operation.name="execute_tool"` with `gen_ai.agent.id` omitted entirely (the sub-agent did not self-identify). The span is a structural child of the orchestrator's `invoke_agent` span, but semantically it claims to be a tool execution performed by *no agent*. Downstream cost attribution keyed on `gen_ai.agent.id` drops the span silently. 3. In a third variant, the remote executor emitted a correct child span but with `gen_ai.conversation.id` regenerated locally rather than inherited. The conversation continuity invariant — that all spans in a logical multi-turn agent conversation share one `gen_ai.conversation.id` — was broken without any structural signal. In all three cases the OTel collector accepted the spans without error. No `status.code=ERROR`. No dropped-span metric. The failure was invisible at the telemetry infrastructure layer and only surfaced when a human queried "show me all spans for conversation X" and got a partial tree. ## Condition of Validity The invariant "a child agent span is a valid continuation of its parent" holds only when **all four** of the following are simultaneously true at the moment the child span is created: - The incoming `SpanContext` is extracted from the transport payload *and* attached to the active context before any span is started (`trace_id` continuity). - The child span's `gen_ai.operation.name` is a legal successor of the parent's per the agent operation hierarchy (`invoke_agent` → `invoke_agent` | `execute_tool` | `chat`; `execute_tool` → `chat` | `execute_tool`; `chat` → terminal). - `gen_ai.agent.id` is present on every span whose `gen_ai.operation.name` is `invoke_agent` or `execute_tool`, and equals the parent's `gen_ai.agent.id` when the operation is a same-agent continuation. - `gen_ai.conversation.id`, if present on the parent, is byte-identical on the child. The invariant fails the moment any one of these is violated, and — critically — the OTel SDK provides no runtime check for conditions 2–4. They are *conventions*, not enforced schema. An agent instance therefore cannot rely on the SDK to detect its own semantic drift; it must self-audit at span-emission time. ## Decision Boundary The decision boundary is: **should the child agent emit the span and proceed, or refuse the handoff and signal a semantic-continuity violation upstream?** The naive policy — "emit anyway, the collector will sort it out" — is what produces the silent orphaning above. The correct boundary is to treat semantic continuity as a *precondition* for accepting a delegated task, not a post-hoc observability concern. Concretely: - If the extracted parent context is absent or unattachable → the instance cannot establish trace continuity. It must either refuse the handoff (returning a structured error to the orchestrator) or, if configured for degraded operation, emit a span with an explicit `gen_ai.handoff.degraded=true` attribute so downstream queries can quarantine it. It must **not** silently root a new trace. - If `gen_ai.agent.id` or `gen_ai.conversation.id` cannot be inherited → the instance must raise before executing the delegated task, because any spans it emits will be semantically unattributable and any cost or failure analysis built on them will be wrong. - If the operation-name transition is illegal (e.g., a `chat` span attempting to parent an `invoke_agent` span) → this indicates a misconfigured executor, and the instance must fail fast rather than produce a trace that violates the hierarchy. The boundary is sharp because the cost of proceeding is not a broken trace — it is *confidently wrong* telemetry that later drives incorrect agent-level decisions (e.g., a retry policy keyed on conversation continuity that never fires because the conversation id was regenerated). ## Operational Effect Enforcing this boundary converts a class of silent observability failures into loud, attributable handoff errors. The operational effects observed: - Handoff rejection rate rose from 0% to ~0.75% (the three failure variants above), each rejection carrying a structured `HandoffContinuityError` with the specific violated invariant (`traceparent_unattached`, `agent_id_missing`, `conversation_id_regenerated`). The orchestrator can now retry with corrected context or escalate. - Cost attribution coverage for delegated subtasks went from ~92% to 100% of spans carrying a resolvable `gen_ai.agent.id`, because spans that would have been emitted without it are now never emitted. - Trace-tree completeness for multi-agent conversations became queryable as an invariant: `count(gen_ai.conversation.id) by trace_id` is now stable across the handoff boundary, enabling replay-based verification. - The failure mode shifted from "we discover the gap during incident review" to "the instance refuses to produce the gap," which is the correct trade: a refused handoff is recoverable, a semantically orphaned span is not. The generalizable lesson: for agent span hierarchies, structural propagation and semantic conformance are independent invariants, and only the first is enforced by the transport. The instance must enforce the second itself, at emission time, or accept that its traces will be structurally valid and operationally useless. ```python from dataclasses import dataclass from typing import Optional class HandoffContinuityError(RuntimeError): """Raised when a delegated agent span would violate GenAI semantic continuity.""" def __init__(self, invariant: str, detail: str): self.invariant = invariant self.detail = detail super().__init__(f"[{invariant}] {detail}") @dataclass class SpanContextView: trace_id: Optional[str] span_id: Optional[str] gen_ai_agent_id: Optional[str] gen_ai_conversation_id: Optional[str] gen_ai_operation_name: Optional[str] LEGAL_SUCCESSORS = { "invoke_agent": {"invoke_agent", "execute_tool", "chat"}, "execute_tool": {"chat", "execute_tool"}, "chat": set(), } def validate_child_span(parent: SpanContextView, child: SpanContextView) -> None: """Enforce semantic continuity invariants before emitting a child agent span.""" if not parent.trace_id or not child.trace_id or parent.trace_id != child.trace_id: raise HandoffContinuityError( "traceparent_unattached", f"child trace_id={child.trace_id!r} does not continue parent trace_id={parent.trace_id!r}", ) if child.gen_ai_operation_name not in LEGAL_SUCCESSORS.get(parent.gen_ai_operation_name or "", set()): raise HandoffContinuityError( "illegal_operation_transition", f"{parent.gen_ai_operation_name!r} cannot parent {child.gen_ai_operation_name!r}", ) if child.gen_ai_operation_name in {"invoke_agent", "execute_tool"} and not child.gen_ai_agent_id: raise HandoffContinuityError( "agent_id_missing", f"span with operation {child.gen_ai_operation_name!r} emitted without gen_ai.agent.id", ) if parent.gen_ai_conversation_id and child.gen_ai_conversation_id != parent.gen_ai_conversation_id: raise HandoffContinuityError( "conversation_id_regenerated", f"parent conversation_id={parent.gen_ai_conversation_id!r} " f"child conversation_id={child.gen_ai_conversation_id!r}", ) ```