Tracing

Trace agent, team, and workflow runs with OpenTelemetry and store spans in a configured database or observability backend.

v2.3.5

A final run response shows the outcome. Tracing shows the model calls, tool executions, and nested agent, team, or workflow operations that produced it. Developers use traces to investigate failures, latency, token usage, and unexpected tool behavior.

Set OpenAI Key

Set your OPENAI_API_KEY as an environment variable. You can get one from OpenAI.

export OPENAI_API_KEY=sk-***

Trace an Agent

Install tracing dependencies

uv pip install -U "agno[os]" openai opentelemetry-api opentelemetry-sdk openinference-instrumentation-agno

Configure database export

Call setup_tracing() once at application startup, before running agents.

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
from agno.tracing import setup_tracing

traces_db = SqliteDb(db_file="tmp/traces.db")
setup_tracing(db=traces_db)

agent = Agent(
    id="support-agent",
    model=OpenAIResponses(id="gpt-5.4-mini"),
    instructions="Answer support questions concisely.",
)

agent.run("Summarize the latest support request.")

Query stored traces

traces, total = traces_db.get_traces(agent_id="support-agent", limit=10)

for trace in traces:
    print(trace.name, trace.duration_ms)

On its first setup, setup_tracing(db=...) installs Agno's DatabaseSpanExporter and instruments agents, teams, and workflows through OpenTelemetry.

Configure tracing once per process, before running agents, teams, or workflows. If a real global OpenTelemetry TracerProvider already exists, setup_tracing() returns without adding an exporter or instrumenting Agno. A second call does not change the database or processing settings. When another integration owns the provider, configure its exporters and AgnoInstrumentor directly.

Traces viewed in AgentOS
Traces stored in SQLite and viewed in AgentOS

Traces and Spans

ConceptDescription
TraceOne complete execution, identified by trace_id
SpanOne timed operation within the trace, such as an agent run, model response, or tool execution
Parent-child relationshipConnects nested operations into the execution hierarchy
Trace and span hierarchy

What Gets Traced

Agno instrumentation captures spans for:

OperationExamples
Agent runsagent.run() and agent.arun()
Model callsModel requests and responses
Tool executionTool calls and results
Team executionLeader coordination and member runs
Workflow executionWorkflow runs and step execution

Spans carry timing, status, relationships, and operation attributes. Trace payloads can include application inputs and outputs. Review captured attributes before sending traces to a shared or external destination.

Choose a Trace Destination

Tracing storage follows the OpenTelemetry configuration in your application:

ConfigurationDestination
setup_tracing(db=...)The selected Agno database through DatabaseSpanExporter
AgentOS(..., tracing=True, db=...)The AgentOS database, available through its API and Control Plane
A custom OpenTelemetry provider instrumented with AgnoInstrumentorThe backend configured by that provider's exporter

Use Agno OpenTelemetry integrations when traces should go to an external observability backend. The exporter configuration determines where those spans are sent.

Immediate and Batch Export

When it creates the tracing provider, setup_tracing() writes each completed span immediately by default. Set batch_processing=True to queue spans and export them in batches.

setup_tracing(
    db=traces_db,
    batch_processing=True,
    max_queue_size=2048,
    max_export_batch_size=512,
    schedule_delay_millis=5000,
)
ParameterDefaultPurpose
batch_processingFalseUse batched export instead of immediate export
max_queue_size2048Maximum queued spans
max_export_batch_size512Maximum spans in one export batch
schedule_delay_millis5000Delay between scheduled batch exports

Next Steps