Skip to main content
A Trace represents one complete agent execution from start to finish. Each trace has a unique trace_id that groups all related spans together.

Trace Attributes

AttributeTypeDefaultDescription
trace_idstrRequiredUnique trace identifier
namestrRequiredTrace name (typically the root span name, e.g., Agent.run)
statusstrRequiredOverall status: OK, ERROR, or UNSET
duration_msintRequiredTotal execution time in milliseconds
start_timedatetimeRequiredWhen the trace started
end_timedatetimeRequiredWhen the trace completed
total_spansint0Total number of spans in this trace
error_countint0Number of spans that errored
run_idOptional[str]NoneAssociated agent/team/workflow run ID
session_idOptional[str]NoneAssociated session ID
user_idOptional[str]NoneAssociated user ID
agent_idOptional[str]NoneAssociated agent ID
team_idOptional[str]NoneAssociated team ID
workflow_idOptional[str]NoneAssociated workflow ID
created_atdatetimeRequiredWhen the trace record was created

Methods

to_dict()

Convert the trace to a dictionary.
trace_dict = trace.to_dict()
Returns: dict

from_dict()

Create a trace from a dictionary.
trace = Trace.from_dict(data)
Parameters:
  • data (dict): Dictionary containing trace data
Returns: Trace

Usage

from agno.db.sqlite import SqliteDb

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

# Get a trace
trace = db.get_trace(run_id=response.run_id)

if trace:
    print(f"Trace ID: {trace.trace_id}")
    print(f"Name: {trace.name}")
    print(f"Duration: {trace.duration_ms}ms")
    print(f"Status: {trace.status}")
    print(f"Total Spans: {trace.total_spans}")
    print(f"Errors: {trace.error_count}")

See Also