A hands-on guide to tracing AI agents with OpenTelemetry, span design, and SDK-level instrumentation for production systems.
Agent TracingLong read

Span Attribute Schemas That Make Recurring Failure Patterns Cluster Themselves

Structured span attributes let AI failure patterns cluster automatically without manual labels.

· 8 min read
Cover illustration for “Span Attribute Schemas That Make Recurring Failure Patterns Cluster Themselves”
Agent Tracing · November 3, 2026 · 8 min read · 1,843 words

Automatic grouping of recurring AI agent failure patterns depends on span attributes that encode failure mechanisms alongside execution status. A practical schema separates tool calls, reasoning, state transitions, and memory operations, then gives each type normalized attributes that clustering can compare across runs. Combined with span embeddings, those attributes let repeated failures group without manual labels or predefined rules for every failure mode.

Why span attributes are the unit that determines whether failures cluster or scatter

A dashboard can look healthy while an agent confidently misclassifies a product. The request completes, latency stays normal, and no exception appears. Yet the agent may have passed a malformed identifier to a tool and mistaken an empty result for evidence of safety. Conventional monitoring records a successful operation.

Span attributes are key/value fields attached to individual operations in a distributed trace. They become the dimensions on which failures can group. Attributes that describe intent, arguments, and interpretation help a clustering algorithm see when different runs share a failure mechanism. Duration and HTTP status cannot establish that relationship alone. Collecting more traces therefore does not solve a schema that records execution but omits meaning.

What the four span types cover and why each one maps to a distinct failure surface

Tool-call spans record tool names, arguments, raw outputs, duration, retries, and errors. Their failure surface is argument construction or tool execution. Reasoning spans record the plan the agent declared, the action it selected, its observation, and its next decision. They expose plan drift and wrong-branch selection that a single model-call record cannot distinguish.

State transition spans capture working memory before and after a step, context edits, and handoff payloads. Their failure surface is context propagation across steps. Memory operation spans record reads and writes to long-term stores, including queries, returned entries, relevance, and freshness. They expose retrieval errors and failures of write isolation.

How the OpenTelemetry GenAI conventions establish the baseline attribute vocabulary each span type starts from

OpenTelemetry provides the vendor-neutral gen_ai.* vocabulary from which an agent tracing schema can begin. Baseline fields include gen_ai.system, gen_ai.request.model, gen_ai.usage.input_tokens, and gen_ai.usage.output_tokens. OpenInference extends this vocabulary with message.tool_calls and tool_call.* fields. Tool results link back through message.tool_call_id on input messages whose role is tool. Correlation preserves which result belongs to which invocation.

The hierarchy preserves a different kind of relationship. An invoke_agent span can have direct chat and execute_tool children, while an invoke_workflow span can wrap multiple agents in a multi-agent system. These relationships provide the baseline for following decisions across calls and handoffs. They do not, by themselves, encode intent, failure category, or policy context. The schema extensions below supply the semantic distinctions that automatic grouping needs.

Tool-call span attributes that make argument and output failures cluster by failure type rather than by tool name

The malformed-SKU case shows why tool success is an inadequate grouping dimension. An agent calls lookup_product_history with a malformed SKU, receives an empty result, interprets “no prior flags” as “no risk,” and confidently classifies the product as safe. Nothing in the conventional status signals identifies the mistake. The span must preserve what the tool received, what it returned, and how the agent used that return value.

tool.name identifies the operation, while tool.argument_schema_match records whether its arguments matched the expected schema. A boolean or enum lets the system compare that distinction across runs, and tool.output_used records whether the downstream model referred to the tool output. Together, these fields separate argument validity from output consumption. They do not make an empty result inherently trustworthy, so the recorded output and reasoning observation remain necessary to distinguish using a result from interpreting it correctly.

tool.error_origin tool.error_origin gives the cluster a failure mechanism. Its enum values are argument_construction, external_api, timeout, and schema_validation. Without that distinction, failures that have different causes can end up under one tool name. With it, argument-construction failures can group across different tools and direct investigation toward the planning step. tool.retry_count adds another dimension, exposing successful-looking runs with silent retry loops that consume tokens or mutate external state.

The output-use field also exposes a separate pattern. When a tool reports an unsuccessful result and the consuming model ignores it, a confident answer can propagate as a completed task. Grouping that behavior separately prevents an output-consumption failure from being mistaken for an external API problem.

Reasoning span attributes that distinguish plan drift from wrong-branch selection from instruction deviation

When tools fail, they at least leave arguments and outputs. Reasoning failures may leave no external error at all. A reasoning span must therefore represent the agent’s intended path and its recorded decisions, rather than relying on the final response to reveal the divergence. reasoning.intent captures the goal derived from the instructions, while reasoning.plan_step identifies the corresponding step in the declared plan. Their relationship makes skipped or out-of-order steps distinguishable from ordinary progression.

reasoning.action_selected records the chosen tool or sub-agent. Paired with intent, it separates tool mismatches on retrieval steps from tool mismatches on validation steps. reasoning.branch_selected identifies the conditional path taken, allowing wrong-branch selection to group separately from broader plan drift. reasoning.observation records the agent’s interpretation of a tool or retrieval result. Parent-child links make that interpretation comparable with the actual output, exposing hallucinated grounding.

Adaptive Influence Graphs for Failure Attribution in Multi-Agent Systems, from AWS and Tel Aviv University, shows why the way traces are represented affects failure attribution. The research finds that failure attribution gets better at each step from raw logs through structured logs and influence graphs to adaptive influence graphs. Component boundaries, action selection, and influence relationships make it easier to trace failed executions to their source than raw text alone does. This supports the schema principle that structured reasoning attributes supply distinctions that a grouping system would otherwise have to reconstruct.

State transition span attributes that surface context loss and handoff corruption across multi-step runs

In longer runs, lost context can look like the model getting worse. The attribution is misleading when the failure is actually a dropped constraint, a lossy summary, or a corrupted handoff. Without state records, the trace leaves that distinction unresolved. state.before_snapshot and state.after_snapshot capture working memory on either side of a step. Structured snapshots let the system compare traces without a person having to read every state description.

The delta between those snapshots is the detectable context edit. When an agent summarizes earlier turns, that edit can show what information was lost through compression. Repeated unexpected deltas can then group as summarization drift. state.step_index places each transition within the run. It distinguishes failures concentrated at later steps from failures distributed throughout execution.

state.context_window_utilization records how much of the context window has been used, so saturation is visible alongside absolute token counts. Alerting at a high saturation threshold can expose the conditions under which earlier context is dropped. For handoffs, state.handoff_payload_hash provides a reference for the payload sent between agents, while the receiving agent’s snapshot records what arrived. The comparison must concern the corresponding payload representation. Without the receiving state, corruption can propagate with no attribution signal.

Memory operation span attributes that distinguish stale reads, wrong-entity retrieval, and cross-user leakage

Cross-user memory leakage can leave a health dashboard green while a span-level cluster exposes repeated mismatches between the requesting session and the memory accessed. memory.session_scope records the user or session governing the operation. Detecting leakage also requires the record to distinguish whose memory was read from whose memory the agent was authorized to read. A query and its result alone cannot establish that boundary. Error rates, latency, and token counts do not substitute for scope.

The remaining attributes separate retrieval failures within that boundary. memory.query preserves the exact query, allowing malformed queries to be distinguished from queries that repeatedly retrieve irrelevant results. memory.retrieved_entry_ids identifies returned entries for comparison with the entity the agent was working on. memory.relevance_scores distinguishes low-confidence retrieval from high-scoring retrieval of the wrong entity. These are different failure mechanisms, even when both produce an unsuitable answer.

Freshness adds a distinction that relevance cannot supply. memory.entry_freshness, recorded as a timestamp or age bucket, separates stale reads from wrong reads. A superseded policy document requires a different fix from an unrelated policy document. Similarly, low-score entries that the agent accepts without re-querying form a recognizable pattern of low-confidence retrieval accepted. Recording scores as attributes makes that pattern available to grouping without parsing a log line.

How attribute cardinality and value normalization determine whether clusters are actionable or too broad to debug

Values with too little distinction merge unrelated failures, while values unique to each run scatter recurring failures into one-offs. Raw exception messages illustrate the second problem. Recording them directly in tool.error_origin can make each occurrence look different despite a shared mechanism. The bounded enum preserves that mechanism while avoiding incidental differences in wording.

Numeric buckets and structured identifiers address related problems. Values such as low, medium, high, and critical for context utilization let failures group by operational thresholds. Retrieved entry IDs need a different treatment. Recording memory.retrieved_entry_ids as a list preserves membership patterns across runs, while concatenating all IDs into one string can create a unique value for every retrieval. Normalization should keep the relationship being compared even as it cuts the number of values.

Model-generated reasoning text is another source of fragmentation. A sentence describing an action can vary even when the selected tool is unchanged. reasoning.action_selected reasoning.action_selected should therefore hold a normalized tool name. The raw text can remain in a span event. Keeping large, run-specific prompts and completions in events likewise separates diagnostic content from the indexed attributes used for grouping.

How do AI observability platforms automatically group recurring failures across agent runs?

A schema-driven clustering pipeline combines span embeddings with typed, normalized attributes. Embeddings represent semantic content, while attributes scope membership through structured dimensions. The combination can distinguish tool argument failures on payment tools from argument failures on retrieval tools without a separately authored rule for each group. The schema supplies the comparison surface. It does not replace the clustering algorithm or the evaluation that identifies failed behavior.

The four span types contribute complementary evidence. tool.error_origin identifies an execution failure mechanism, while reasoning.intent places the selected action against its goal. state.step_index locates context failures within a run, and memory.session_scope preserves the boundary needed to detect inappropriate memory access. Failures that share several relevant dimensions can group even when their raw traces differ. Shared attribute values also give the system a way to name the cluster without a predefined failure label.

Predefined rules cover only failures that someone has already thought of. Structured attributes instead create dimensions on which an unanticipated pattern can become visible. That distinction is the operational value of deliberate schema design. A cluster can group unsuccessful runs and point toward argument construction, branch selection, context propagation, or memory isolation. Investigation begins at the failure surface encoded in the spans.

Once a cluster’s failure is fixed, its traces can become cases in the offline evaluation set, using the same rubric that scores live spans. The regression test checks that future runs avoid the failure represented by that cluster, building test coverage from production failures while automating case creation for engineers.

Filed underAgent Tracing

More in Agent Tracing