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.)
Span Types
| Type | Description |
|---|---|
text | Text operations, agent messages, thinking |
tool | Tool invocations |
llm | LLM API calls (OpenAI, Anthropic) |
audio | Audio processing (for voice agents) |
function | Function executions |
Listing Traces
Get traces for an agent:Query Parameters
| Parameter | Description |
|---|---|
agent | Filter by agent UUID |
product_id | Filter by product UUID |
name | Filter by trace name |
started_after | Filter by start time |
limit | Results per page (default 50) |
offset | Pagination offset |
sort | Sort field (e.g., -started_at) |
Getting a Trace with Spans
Span Details
Each span contains:| Field | Description |
|---|---|
name | Operation name |
span_type | Type (text, tool, llm, audio, function) |
parent | Parent span UUID (for nesting) |
started_at | When the operation started |
ended_at | When it completed |
input_text | Input to the operation |
output_text | Output/result |
error | Error message if failed |
metadata | Additional structured data |
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 anAgentUsage 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):Debugging with Traces
Common debugging patterns:Find Failed Runs
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.