# What structural signals indicate trace-context loss at the agent-to-tool span boundary under OpenTelemetry GenAI semantic conventions **Date of Record:** 2026 November 27 **Scope:** Applies to agents emitting OTel spans with `gen_ai.*` attributes where a tool call crosses a process or transport boundary (MCP server, subprocess, remote HTTP tool) and the child span is expected to inherit the parent agent span's trace context. Does not apply to in-process tool functions traced within a single runtime, nor to pure metric/log emission without spans. ## Core Distinction The GenAI semantic conventions define `gen_ai.operation.name` (e.g. `chat`, `execute_tool`, `invoke_agent`), `gen_ai.tool.name`, `gen_ai.agent.id`, and — critically — the requirement that tool-call spans be *children* of the invoking agent span so that the trace tree reconstructs the causal chain `invoke_agent → chat → execute_tool`. This is a *structural* claim about parent-child linkage, not merely about attribute presence. The failure mode is this: a span can carry a perfectly valid, well-formed set of `gen_ai.*` attributes, pass every schema validator, and still be structurally orphaned — because W3C `traceparent` propagation was dropped at the tool transport boundary while the span was still created locally with a *new* trace ID. The resulting trace is not "missing data"; it is *silently re-rooted*. The GenAI attributes look correct. The trace ID is valid. The parent link is simply absent, and the agent's execution graph is now two disconnected trees that no downstream evaluator will ever stitch back together. This is the boundary condition: **attribute conformance and trace-context continuity are independent invariants, and the GenAI conventions only specify the former.** ## What Was Observed In a multi-step agent invoking an external MCP tool server over stdio, the following was reproducible. The orchestrator emitted: - `invoke_agent` span, trace ID `4bf92f...`, span ID `00f067...` - `chat` child span, same trace ID, parent `00f067...` - `execute_tool` span created *inside the MCP server process*. The MCP server created its `execute_tool` span with `gen_ai.tool.name="search_docs"`, `gen_ai.operation.name="execute_tool"`, correct status, correct duration. But because the MCP SDK's stdio transport did not inject the `traceparent` header into the JSON-RPC `params._meta` envelope (and the client did not extract it), the server's tracer started a **fresh root span** with a new trace ID `9c1a44...`. Structural signals that flagged this, in order of reliability: 1. **Trace-ID cardinality per agent run.** A single agent invocation should yield exactly one trace ID across `invoke_agent`, all `chat` spans, and all `execute_tool` spans. Observing `count(distinct trace_id) > 1` scoped to one `gen_ai.agent.id` execution is the primary signal. 2. **Orphaned `execute_tool` spans with no `invoke_agent` ancestor.** Query the span tree: any `execute_tool` span whose ancestor chain contains no `gen_ai.operation.name="invoke_agent"` is a re-rooted span, regardless of attribute validity. 3. **`parent_span_id == ""` on a non-root operation.** `execute_tool` is by definition a non-root operation; an empty parent is structurally impossible in a correct trace. 4. **Missing `traceparent` in transport envelope.** At the protocol layer, the JSON-RPC `_meta` (or HTTP header) carrying the tool request lacked `traceparent`/`tracestate`. This is the *cause*; signals 1–3 are the *symptoms*. The insidious part: latency, error rate, and token metrics all remained correct. Only the *topology* was wrong, which is exactly the dimension that tool-call attribution and failure-replay depend on. ## Condition of Validity The invariant holds — and this failure is bounded — only when all of the following are true: - The tool executes in a **separate execution context** (process, host, or network hop) such that in-memory context propagation cannot apply and wire-level `traceparent` injection is the sole carrier. - The downstream runtime uses an OTel SDK that, absent an extracted remote context, **defaults to starting a new root** rather than erroring. (Most SDKs do this silently; this default is the enabling condition.) - The agent's tool-call span is expected to be a child of the agent span per the `invoke_agent → execute_tool` causal model. If the tool is intentionally fire-and-forget and correlation is done by a business key instead, this boundary does not apply. If propagation is done via a message queue with its own trace-context propagation (e.g. W3C context in message headers) and that path is correctly instrumented, the failure does not occur. The boundary is specifically the *uninstrumented* transport seam. ## Decision Boundary The decision is whether to treat a well-attributed `execute_tool` span as *valid telemetry* or as a *continuity violation requiring rejection*. - **Accept-and-correlate** is correct only when the tool is genuinely asynchronous/detached and a stable business correlation ID (`gen_ai.agent.id` + a run ID) is present on both sides, allowing offline stitching. In that case, orphaned trace IDs are expected and the invariant is "correlation ID present on both spans," not "shared trace ID." - **Reject** is required when the span is synchronous and causal: a synchronous `execute_tool` with no `invoke_agent` ancestor must be flagged as a continuity violation, because any downstream evaluator that reconstructs the agent's reasoning chain will silently omit the tool's contribution — producing a *plausible but wrong* execution graph. The trap is choosing accept-and-correlate by default because "the attributes are fine." Attribute conformance must not be used as evidence of trace continuity. The two checks are orthogonal; the decision boundary is crossed the moment a synchronous tool boundary is crossed without a propagated `traceparent`. ## Operational Effect When this violation goes undetected, three concrete degradations follow: 1. **Broken causal replay.** Post-hoc failure analysis that walks the span tree from `invoke_agent` will not reach the tool span, so tool-induced errors (bad retrieval, injected content) appear as unexplained divergence in the `chat` span's output — the agent "hallucinated" with no visible cause. 2. **Miscounted tool attribution.** `execute_tool` latency and error metrics roll up under a phantom root trace, so per-agent cost/latency attribution undercounts tool time by exactly the orphaned fraction. 3. **Injection invisibility.** A prompt-injection payload delivered through a tool result crosses the same boundary; if the tool span is orphaned, the poisoned input's provenance is severed from the agent span that consumed it, defeating the primary forensic use of the trace. The guardrail is a **continuity assertion at span creation**, not at export: the tool-side tracer must refuse to create an `execute_tool` span with an empty parent when `gen_ai.operation.name="execute_tool"` and the call is synchronous. This converts a silent re-root into a loud, local failure at the exact seam where `traceparent` was lost. ```python from dataclasses import dataclass class TraceContextContinuityError(RuntimeError): """Raised when a non-root GenAI operation span is created without a parent.""" @dataclass class SpanContext: trace_id: str span_id: str parent_span_id: str | None def assert_tool_span_continuity( ctx: SpanContext, gen_ai_operation_name: str, synchronous: bool, ) -> None: # execute_tool is, by the GenAI causal model, always a child of an # invoke_agent/chat span. A missing parent means traceparent was dropped # at the transport boundary and the SDK silently re-rooted the trace. if gen_ai_operation_name == "execute_tool" and synchronous: if not ctx.parent_span_id: raise TraceContextContinuityError( "execute_tool span created with no parent (trace_id=" f"{ctx.trace_id}, span_id={ctx.span_id}); traceparent was " "not propagated across the tool transport boundary. " "Refusing to emit a re-rooted span that severs the " "invoke_agent -> execute_tool causal chain." ) # Non-synchronous tools may legitimately be correlated by business key # rather than shared trace ID; that case is out of scope for this check. def emit_tool_span( ctx: SpanContext, tool_name: str, synchronous: bool = True, ) -> None: assert_tool_span_continuity(ctx, "execute_tool", synchronous) # ... actual span emission with gen_ai.tool.name, gen_ai.operation.name ... _ = tool_name ```