Skip to main content

Tracing

Bedrock provides full observability into agent execution through traces and spans. Every agent run creates a detailed record of what happened.

Traces and Spans

  • Trace: A complete record of an agent run
  • Span: A single operation within a trace (LLM call, tool execution, etc.)
A Trace (one agent run) contains nested Spans:
  • run_agent
    • turn_0openai_api_call (LLM), list_tasks (tool), assistant_message (text)
    • turn_1anthropic_api_call (LLM), create_task (tool), sleep (tool)
    • …additional turns

Span Types

Listing Traces

Get traces for an agent:
Response:

Query Parameters

Getting a Trace with Spans

Response:

Span Details

Each span contains:

LLM Cost Tracking

LLM spans include cost metadata:

Creating Custom Traces

You can create traces programmatically for custom operations:

Usage Records

When a trace ends, Bedrock automatically creates an AgentUsage record that aggregates all LLM costs from that trace. Query these via the agent usage endpoint:

Flagging Spans for Review

Mark spans that need attention (e.g., incorrect agent responses):
Flagged spans can be used for evaluation and fine-tuning. Remove a flag:

Evals (Flagged Span Corrections)

Flagged spans are stored as eval test cases that you can browse and curate via /api/tracing/evals/: For running full scenario-based evaluations, see Evaluations.

Debugging with Traces

Common debugging patterns:

Find Failed Runs

Look for traces with non-null error field.

Analyze Tool Usage

Filter spans by type to see which tools were called:

Check Token Usage

LLM spans contain detailed token counts in metadata for cost analysis.

Best Practices

Review Failed Traces

Check the error field to find and fix issues.

Monitor Costs

Use LLM span metadata to track spending.

Flag Bad Outputs

Use the flag endpoint to mark incorrect responses.

Trace Custom Ops

Create traces for operations outside agent runs.