# Inspect agent runs

> Inspect session events with Debug and retrieve trace spans to investigate individual agent behavior.

# Inspect agent runs

Use session events and traces to investigate an individual interaction. A trace breaks one run into the model calls, tool calls, and other recorded operations that made it up, each with its own duration and status. Inspect a run when you need to explain what a metric reported, or when one interaction behaved differently from the rest.

## Before you begin

You need permission to inspect the agent and its sessions. Metric-viewing permission alone does not grant trace access. The trace API accepts the account roles `agent_viewer`, `agent_developer`, `agent_administrator`, `viewer`, `administrator`, and `owner`. Its list operation also supports agent-scoped authorization.

Start from a known session when you can. Record the agent key, session key, and relevant UTC window. Treat session content and tool arguments as potentially sensitive. Do not include credentials or unnecessary content when sharing diagnostic evidence.

## Inspect a session in the Console

1. Open **Dev tools > Agents**, select the agent, and open **Sessions**. Open the conversation you want to inspect.
2. Select the **Debug** action, identified by a bug icon. The **Debug** drawer lists the available events with their types and timestamps.
3. Expand an event to inspect its JSON. Use **Expand all** or **Collapse all** to control the list. The ordering choices are **Order most recent events at top** and **Order first events at top**.
4. Compare the event types, recorded timestamps, and payloads relevant to the issue. An empty drawer displays **No events found**, which describes this session's events only.
5. With an existing session open, select **View traces** to open the trace view filtered to that session. See [Read a trace in the Console](#read-a-trace-in-the-console).

{/* Recapture the open Debug drawer from Dev tools > Agents > [agent] > Sessions with one event accordion expanded, ideally a tool_output so the JSON payload is visible. Keep the ordering select and the Expand all footer in frame. The drawer renders the raw event verbatim, so use an agent whose content is entirely yours. */}

**Expected result:** you can identify the relevant event payloads and trace records for that session. These are different views of the activity, not interchangeable counters. For creating new activity rather than inspecting existing activity, see [Agent sessions](../agents/sessions.md).

## Read a trace in the Console {#read-a-trace-in-the-console}

The trace view lives at **Build > Observability > Traces**, alongside the **Metrics** tab of the same section. The same view is also available as a **Traces** tab inside an agent, at **Dev tools > Agents**, scoped to that agent. You can open it directly from the navigation, or through a **View traces** action that carries a filter with it.

Three actions lead there, and they do not pre-fill the same filters:

| Where you select **View traces** | What the trace view is filtered to |
| --- | --- |
| An open session | The session key; the agent key if available; and, if the session's creation time is available, a custom range beginning five minutes before that time |
| A row in an agent's **Sessions** list | That session key |
| A row in the **Agents** list | That agent key |

The trace view reads its filters from the URL, so an entry point that sets only one of them leaves the rest at their defaults rather than carrying over your previous selection. Arriving with only a session key, for example, applies no agent filter. Check which filters are in effect before concluding that a run was not recorded.

A trace is presented as a waterfall. Each row is one span, with **Span**, **Duration**, and **Timeline** columns, where the timeline bar places the span within the trace's overall duration. Select **Details** in the **Actions** column to open that span's detail panel.

{/* Recapture a trace whose Spans stat shows no trailing plus, meaning every child span is loaded. Expand each row with a chevron first, since the view loads only top-level invoke_agent spans and fetches children on demand. Leave the span Details panel closed; it reads span content and can surface agent instructions. */}

## Retrieve traces and spans

Use `GET /v2/agent_analytics/traces` to list trace records with optional `agent_key`, `session_key`, status, and time filters. Use a returned trace ID with `GET /v2/agent_analytics/traces/{trace_id}/spans` to read its spans.

Follow `metadata.page_key` when another page is present. A span's `parent_span_id` identifies its parent so you can reconstruct the tree. Do not assume one trace per session or equate all spans with agent invocations. See the [measurement model](./index.mdx#measurement-model).

Span content is excluded by default. Set `include_content=true` only when the available input/output messages or tool arguments are needed. This can expose more sensitive data than aggregate metric reads.

Use the generated [List agent traces](/docs/rest-api/list-traces), [Get agent trace](/docs/rest-api/get-trace), and [List spans in a trace](/docs/rest-api/list-trace-spans) references for operation-specific parameters and authorization.

## Use inspection to check a metric

1. Match the agent and operation to the metric definition. An `invoke_agent` count and an `execute_tool` count measure different observations.
2. Match the depth population. A custom metric with **Top-level sessions only** excludes sub-agent sessions and missing depth values.
3. Match the metric's time window and returned bin boundaries. A custom metric uses the end of the span to assign a time bin. A trace-list filter on start time is not an equivalent metric filter.
4. Account for [backfill and coverage limits](./custom-metrics-reference.md#coverage-and-retention). Use inspection to explain a discrepancy, not to assume that every older span remains available for reconciliation.
5. Check whether the metric selects `evaluate_run_condition`. Trace reads currently omit that operation, so inspection cannot confirm those observations. See [requests rejected before an agent runs](./custom-metrics-reference.md#requests-rejected-before-an-agent-runs).

When reporting an unresolved issue, share the metric name if relevant, agent/session keys, UTC window, status/error detail, and trace IDs. Include event content only as necessary.

## Related

- [Create and verify a custom metric](./custom-metrics.md)
- [View dashboards](./dashboards.md)
- [Query metrics from your application](./query-metrics-api.md)
- [Agent sessions](../agents/sessions.md)
