
OpenTelemetry GenAI Semantic Conventions Agent Spans Official Docs: A Practical Walkthrough
Building an AI agent is one challenge. Understanding why it made a particular decision, called a tool, or handed work to another agent can be just as important. That is where tracing becomes useful, turning a complicated request into a visible sequence of operations that teams can inspect, measure, and improve.
The OpenTelemetry GenAI semantic conventions agent spans official docs provide a shared vocabulary for recording those operations. Rather than letting every framework describe agent activity differently, the conventions help developers capture consistent trace data across models, tools, services, and observability platforms.
Pydantic Logfire connects agent observability and evaluation
Pydantic Logfire is an OpenTelemetry-native observability and evaluation platform for production AI applications. It brings LLM calls, agent spans, tool activity, API requests and downstream services into a shared trace, regardless of the framework used to build the agent.
That shared context matters when an agent produces an unexpected result. Engineers can investigate the model interaction and its supporting services, then use datasets and evaluators to test whether a change improves the outcome.
For teams implementing the GenAI semantic conventions, Logfire provides a unified place to inspect telemetry, investigate production failures and evaluate agent quality. Pydantic AI is an optional integration, not a prerequisite.
Because it is model-agnostic, it can support agents built around a broad range of providers while preserving a consistent development experience.
What agent spans are designed to show
In OpenTelemetry, a trace represents the journey of one request through a system. A span is a timed record of one unit of work within that journey. For a traditional web service, a span might represent a database query or an HTTP request. In a GenAI application, it may represent a model call, a tool execution, or an agent deciding how to proceed.
An agent span focuses on the agent-level operation. It provides context for work that may involve several smaller actions, such as interpreting a user question, selecting a tool, delegating a subtask, and assembling a final answer. This higher-level view matters because model calls alone rarely explain the full behavior of an agentic application.
The conventions aim to make these traces portable. A dashboard or tracing backend should be able to recognize the purpose of recorded AI activity without relying on one vendor’s private field names.
That consistency is especially helpful when a system uses multiple models, tool providers, or agent frameworks.
The building blocks of an agent trace
An agent trace commonly contains a parent span for the broader request and child spans for the work performed during that request. The parent might represent an incoming API request, while a child agent span records the agent’s orchestration work. Beneath it, model invocations and tool operations can appear as further children.
The official conventions use gen_ai naming to identify AI-related telemetry. Agent-oriented data is intended to distinguish the agent itself from the model it uses or the external tool it calls. This distinction prevents a trace from becoming a flat list of opaque events and helps readers understand who initiated each step.
A useful trace does not need to expose every internal detail. It should record enough context to answer practical questions: which agent handled the request, what operation occurred, how long it took, whether it succeeded, and where the work moved next.
Trace element |
What it represents |
Why it helps |
Parent request span |
The user request or application workflow |
Links AI activity to the broader service transaction |
Agent span |
The agent’s orchestration work |
Shows responsibility for planning, delegation, and coordination |
Model span |
A call to an LLM or embedding model |
Reveals model latency, errors, and usage patterns |
Tool span |
An external function, API, search, or database action |
Shows what the agent used to complete the task |
Events and status |
Notable moments and outcome information |
Makes failures and unusual behavior easier to investigate |
How to read the official documentation without getting lost
The OpenTelemetry documentation can feel dense because it is written as a specification rather than a tutorial. Start by identifying the signal type, which is usually tracing for agent spans, then look for the span name, operation name, required attributes, recommended attributes, and status guidance. Each part serves a different purpose.
Span names make trace views readable at a glance. Operation names provide a more structured classification of what happened. Attributes add the supporting facts, such as the relevant agent identity, model information, request characteristics, or tool details. Together, they allow both humans and software to interpret a trace reliably.
Pay close attention to stability labels and version notes. GenAI semantic conventions have evolved as AI application patterns have matured, so an attribute or recommended approach may change between specification releases. The safest implementation strategy is to use the documented conventions for the version adopted by your telemetry libraries and review release notes before upgrading.
Avoid assuming that every available attribute should be collected. The goal is useful observability, not exhaustive capture.
A practical approach to instrumenting an agent
Begin with the request boundary. When an application receives a user prompt or starts a scheduled workflow, create or continue the trace context there. This gives every later operation a shared trace ID, allowing a reader to follow the complete path from trigger to result.
Next, create an agent span around the orchestration stage. That span should cover the period in which the agent evaluates the task and coordinates its next actions. Model calls, retrieval steps, handoffs, and tool executions should then be represented as nested work where the instrumentation supports it.
Finally, record outcome data carefully. Use span status to indicate success or failure, and capture error details in a controlled way. Logs and events can add diagnostic context, but sensitive prompts, private documents, credentials, and personally identifiable information should never be copied into telemetry without a deliberate privacy policy.
Implementation step |
Recommended focus |
Common mistake to avoid |
Define the trace boundary |
Start at the application request or workflow trigger |
Creating isolated spans with no shared request context |
Instrument the agent |
Capture the agent-level orchestration period |
Treating every model call as the whole agent workflow |
Add child operations |
Trace model, tool, and handoff activity separately |
Combining unrelated operations into one oversized span |
Set status and errors |
Make failures clear and actionable |
Recording vague errors without the relevant context |
Review privacy controls |
Limit data to what operators truly need |
Sending raw prompts, secrets, or customer data by default |
Making traces useful for real teams
A technically correct trace is not automatically useful. Teams should decide what questions they want observability to answer. For example, they may need to know whether an agent fails before calling a model, which tools create the most delay, or whether handoffs increase completion time.
Naming discipline has a large effect on day-to-day usability. Clear span names and stable agent identifiers make dashboards easier to filter, compare, and alert on. If the same agent is called by different services, consistent metadata also helps teams separate application-level problems from model or tool issues.
Sampling is another practical consideration. Capturing every trace can be expensive or unnecessary at scale, yet collecting too little makes incidents difficult to diagnose. Many teams retain errors and slower requests at a higher rate, while using a representative sample for normal traffic.
Good observability is not about watching every action forever. It is about keeping enough trustworthy evidence to improve reliability, cost, latency, and user experience.
Common pitfalls when working with GenAI conventions
One frequent mistake is treating an agent as a single model request. Some simple assistants work that way, but agents often perform several steps and may revisit a decision after receiving tool output. Without an agent-level span, that broader workflow is difficult to recognize in a trace.
Another issue is mixing identities. The agent name, model name, tool name, end user, and service name describe different things. Keeping them distinct prevents misleading dashboards, especially when many agents share the same underlying model or when one agent uses several tools.
Teams can also over-instrument before they understand their operational needs. Start with a small, well-structured set of spans and attributes, validate that traces answer real debugging questions, then expand coverage where it adds value.
Turning agent traces into dependable insight
OpenTelemetry GenAI agent spans give AI systems a common language for describing orchestration, model activity, tool use, and outcomes. By following the official conventions, keeping parent-child relationships intact, and collecting only meaningful context, teams can turn an opaque agent workflow into a system they can confidently operate and refine.