Monitor agents
Create and verify a custom metric
Custom metrics let you measure what is specific to your deployment, such as how often a particular tool is reached, how many model calls a workflow spends, or how much of your traffic comes from a given caller type. Built-in metrics already cover the common operational questions: activity, latency, token use, and errors.
Open Dev tools > Custom metrics to define which recorded operations a metric selects, how it summarizes them, and which agent and sessions it covers. Your metrics are charted on Build > Dashboards and available through the metrics API.
This page creates a count of recorded top-level invocations for one agent, then checks the metric against that agent's activity. The custom metric reference is the canonical list of supported fields, aggregations, and limits.
How a custom metric is computed
The platform computes each metric as new activity arrives, stores the result as a time series, and serves the stored series to the dashboard and the API. Reading a metric never reads your traces.
Two properties of the computation affect how you plan a metric.
A filter reads one span at a time. A span is a single recorded operation with its own attributes, such as one agent invocation, one model call, or one tool call. The Filter step calls each span a row: "Rows where this is true feed the metric." Your filter is evaluated against each row in isolation. It cannot compare one row with another, read the rest of the session the row belongs to, or notice that something happened twice. You cannot measure anything that depends on those relationships. See filter limits.
What a metric measures is fixed when you create it. If a filter could be edited, a stored series would change meaning partway along, and a single chart would mix two populations across the edit. Because the measurement is fixed, a metric means the same thing for its entire life, which is what makes it safe to compare one month against another. In exchange, you do the thinking before you create the metric. To change a measurement, create a second metric and keep the first until you have compared them.
Create metrics before you need them
Backfill is bounded by the configured lookback, available traces, and the metric's retention. Creating a metric can compute data from before its creation, but cannot recover activity outside those bounds.
Define important measurements early rather than relying on backfill to reconstruct an incident after the fact.
Decide up front what you intend to compare
Some questions need two metrics. A tool error rate needs both the errors and the calls, and tokens per session needs both the tokens and the sessions. The platform computes each metric independently and does not divide one by another, so you create both and divide them when you read.
Create such a pair together to simplify verification. Matching creation dates do not by themselves establish comparable coverage, because a later-created metric can backfill earlier activity, and two metrics created together can progress or fail independently.
Before dividing, verify matching computed coverage, compatible retention, the same agent scope and depth choice, and aligned read boundaries. Choose a window covered by both metrics and distinguish the numerator's condition from the denominator intentionally. An all-agent numerator over a single-agent denominator measures different populations. Treat a zero denominator as undefined.
Name the metric after the question it answers
The name is fixed at creation and is the identifier your application passes to the API, so it outlives the Console session in which you chose it. Name it after the question it answers. A name that describes the current filter becomes misleading once you create a better metric alongside it.
Before you begin
You need an account with custom metrics enabled and permission to manage them. See metrics permissions. To inspect the source activity, you also need session and trace access.
Choose an agent that you are authorized to inspect. Use an existing completed top-level interaction with a known time, or, if authorized to run it, use its Preview tab to send a test message and wait for a response. See Create a session. Avoid an agent with side-effecting tools unless those effects are intended.
Record the agent key and a time window containing the completed activity. Use View traces to identify recorded invoke_agent activity for that agent. A transcript message alone does not prove that a matching span is available. Do not assume a test message always adds exactly one to a metric.
Plan before you create
These settings are fixed after creation: Name, Agent scope, filter, aggregation, dimensions, and the Top-level sessions only choice. For why, see how a custom metric is computed. A replacement starts its own computation and backfill, and does not inherit the old metric's computed history.
This walkthrough uses one agent, Count, top-level sessions only, and no dimensions. Its result is not a count of unique sessions or people. If you need an all-agent metric that the dashboard can narrow later, read dimensions before creating a different metric.
1. Describe and scope the metric
- Open Dev tools > Custom metrics and select Create metric. The wizard opens at Details.
- Set Title to
Agent invocations. Enter an unused name such asusage.invocationsin Name. The Console addscustom., producingcustom.usage.invocations. - Enter a Description, such as
Recorded top-level invocations for the selected agent. Set Category tousage, choose the agent you identified above under Agent, and set Unit toinvocations. - Keep the default Retention for this walkthrough, then select Next. You reach Filter.
Check: the selected agent is the one whose activity you recorded. Unit is a label, not a conversion or calculation.
2. Select invocations
Enter this expression in Expression (optional):
Select agent invocations
Code example with sql syntax.1
Leave Top-level sessions only on and select Next.
The Filter step offers two shortcuts above the expression field. Start from an example opens a list of ready-made expressions you can insert and edit. Browse fields opens a searchable list of the span and session paths available in this context, and inserts the one you select at the end of the expression. The Measure step offers the same browser for choosing an aggregation field, where it is restricted to the types that aggregation accepts.
Check: the saved filter will also require depth zero. This excludes sub-agent sessions and spans without a recorded depth. It is not a filter for all spans inside a trace. See session depth.
3. Count and save
- In Measure, choose Count under Aggregation. Count needs no value field. Leave Dimensions empty for this single-agent example.
- Select Create metric. You return to the custom-metrics list.
- Find the exact metric name you chose and check its Agent, Aggregation, and Status.
Check: the stored scope names your agent and the aggregation is Count. Creation can succeed before any chart data is available.
4. Verify the result
- Open Build > Dashboards and choose a window containing the recorded activity. The window must comply with the query-window limits.
- Find the chart for your metric. Check the same agent, time window, and top-level population you used above. Do not compare it with an all-agent or all-depth total.
- If the chart has no observations, follow the diagnostic sequence below. If it has data, inspect a contributing run to confirm that the selected operation and agent match the intended measurement.
- If you need to reconcile a numeric total, use the metrics read workflow and recorded spans, account for returned bin boundaries, and include only the matching population. A backfilling metric or unavailable trace history is not sufficient evidence for an exact reconciliation.
Success means: the metric exists with the intended immutable settings, its selected window has computed observations, and the inspected activity matches the population you intended. A nonzero chart shows that something matched, so confirm the population by inspecting a contributing run.
If the chart is empty
Work through these checks in order rather than deleting and recreating the metric:
- Confirm identity and scope. Match the metric name and agent. Make sure the chosen window contains the activity's end time.
- Inspect Status. For Error, read the detail beside the status. For Disabled, an authorized editor can resume computation. For Backfilling, historical bins can still be incomplete, and backfill has no guaranteed completion time.
- Verify matching observations. Inspect recorded activity for the chosen agent and operation. The depth-zero condition excludes missing depth and sub-agent sessions. A transcript or a built-in total can cover a different population.
- Check coverage. Historical traces might no longer be available for backfill. Review coverage and retention. Do not interpret No data yet in isolation.
- Escalate with evidence if unresolved. Provide the metric name, agent scope, UTC window, status/error detail, and relevant trace IDs to your account administrator or support contact. Do not include API keys or sensitive span content unnecessarily.
Manage the metric
In the custom-metrics list, Backfilling means historical computation is in progress, Active means new data is being computed, Disabled means computation is paused, and Error means computation failed. The lifecycle reference explains retained data and Data since.
When editing, Computation > Compute this metric pauses or resumes computation. Resuming starts backfill from traces still available. Descriptive settings and retention can be changed, but changing the measurement requires a new metric.
Edit metric JSON
Select Edit JSON in the wizard header to open Edit metric JSON. Applying JSON replaces values across the wizard steps. Review those steps before saving. The immutable settings remain fixed. For programmatic use, the supported surface is reading metrics.
Reference topics
The custom metric reference holds the definitions behind each wizard choice:
- Supported aggregations
- Field vocabulary
- Session depth
- Dimensions
- Coverage and retention
- Measurement recipes
- Filter limits