What to Measure: Metrics, Dashboards and SLOs
You cannot fix what you cannot see. Measure outcomes first, then the steps, tokens and time behind them.
Observability is being able to work out what your system did, and why, from what it records. For agents, watch five things together: task success, latency, cost and tokens, errors and safety events. Set targets for the ones users feel, and alert when you are using up the allowed failures too fast.
What you will learn: what to record, how to define and calculate key measures, dashboard design, objectives and alerts, a metrics reference, standard naming and a reference architecture.
Prerequisites: The Agent Loop: Observe, Reason, Plan, Act, Reflect. Running a web service helps but is not required.
Why agents need more than uptime
An ordinary service that responds quickly without errors is probably working. An agent can respond quickly, return success and still have done the wrong thing. It can also quietly take twice as many steps after a change, doubling cost while every dashboard of server health stays green.
| Signal type | Answers | Example |
|---|---|---|
| Metrics | How much and how often? | Success rate, slow-end latency |
| Traces | What happened in this run? | Plan, model call, tool call, result |
| Logs | What details were recorded at a moment? | "Approval refused by policy rule 7" |
| Evaluations | Was it good? | Sampled grade for grounding |
Metrics tell you something is wrong, traces show where and logs and grades explain why. Tracing is covered in Agent Tracing and OpenTelemetry.
The measures that matter
| Area | Core measures |
|---|---|
| Outcome | Task success, escalation rate, human correction rate, repeat contact |
| Latency | Total time, time to first output, time per step, at median and slow end |
| Cost | Input and output tokens, cached tokens, cost per run and per successful task |
| Reliability | Error rate by type, timeouts, retries, limit stops |
| Behavior | Steps per task, tool calls per task, loop detections |
| Safety | Blocked actions, refused approvals, access denials, guardrail triggers |
| Capacity | Concurrent runs, queue age, rate-limit responses |
Use percentiles, not only averages
If nine runs take 3 seconds and one takes 63, the average is 9 seconds, a number nobody experienced. The median (p50) shows the typical case; p95 or p99 shows the unlucky one. Agent latency often has a long tail, because a few runs take many more steps. Do not average percentiles from separate servers; compute them from the underlying data or from histograms.
Define each measure precisely
"Success rate" can mean five different things. Write down the numerator, the denominator and the exclusions.
| Measure | Definition to agree |
|---|---|
| Task success | Tasks verified complete ÷ tasks started, including abandoned ones |
| Cost per successful task | All spend, including failures and retries ÷ successful tasks |
| Escalation rate | Tasks passed to a person ÷ tasks started |
| Tool error rate | Failed calls ÷ attempted calls, per tool |
| Limit-stop rate | Runs ended by step, time or budget limits ÷ runs |
Where success cannot be verified automatically, use a proxy, label it as a proxy and check it regularly against graded samples.
What to record for every run
Good measures start with one well-formed record per run and one per step. If these fields exist, most charts are simple queries.
| Field | Why you will want it |
|---|---|
| Run id, session id and trace id | Join metrics to the story of one run |
| Agent, release, prompt and model versions | Tie a change in numbers to a change in the system |
| Task type and user group | Find who is affected |
| Start, end and time waiting for people | Separate system delay from human delay |
| Token counts per model call | Calculate cost and spot context growth |
| Tool name, outcome and error class per call | Locate failing integrations |
| End reason | Completed, escalated, limit reached, failed or canceled |
| Outcome verdict and who judged it | Distinguish verified success from assumed success |
The end reason is small and valuable. A rising share of runs stopped by a step limit is often the earliest sign that something changed, well before users complain.
From run records to decisions
This program creates 400 synthetic run records in which a tool starts failing in the last quarter. It calculates success, latency percentiles, cost per success and error budget burn. The data and prices are invented for the example.
"""Turn run records into the numbers a dashboard and an alert need."""
import math
import random
from collections import Counter
rng = random.Random(11)
RUNS = []
for i in range(400):
bad_hour = i >= 300 # a tool starts failing late in the day
tool_error = rng.random() < (0.20 if bad_hour else 0.02)
ok = not tool_error and rng.random() < 0.97
RUNS.append({
"ok": ok,
"error": "tool_timeout" if tool_error else (None if ok else "wrong_result"),
"seconds": rng.lognormvariate(1.6, 0.5) + (12 if tool_error else 0),
"in_tok": rng.randint(4000, 12000), "out_tok": rng.randint(300, 900),
})
PRICE_IN, PRICE_OUT = 3.0, 15.0 # example prices per million tokens
SLO = 0.95 # target share of successful runs
def percentile(values, q):
ordered = sorted(values)
return ordered[max(0, math.ceil(q * len(ordered)) - 1)]
def summary(runs):
good = sum(r["ok"] for r in runs)
cost = sum(r["in_tok"] * PRICE_IN + r["out_tok"] * PRICE_OUT for r in runs) / 1e6
secs = [r["seconds"] for r in runs]
return {"success": good / len(runs), "p50": percentile(secs, 0.50),
"p95": percentile(secs, 0.95), "per_success": cost / good,
"burn": (1 - good / len(runs)) / (1 - SLO)}
for label, runs in [("all day", RUNS), ("first 300", RUNS[:300]), ("last 100", RUNS[300:])]:
s = summary(runs)
print(f"{label:9} success {s['success']:.1%} p50 {s['p50']:.1f}s p95 {s['p95']:.1f}s"
f" ${s['per_success']:.4f}/success burn {s['burn']:.1f}x")
print("errors:", dict(Counter(r["error"] for r in RUNS if r["error"])))
long_burn, short_burn = summary(RUNS[-100:])["burn"], summary(RUNS[-25:])["burn"]
print("page on-call" if long_burn > 2 and short_burn > 2 else "no page")
Output:
all day success 88.8% p50 5.3s p95 16.4s $0.0371/success burn 2.2x
first 300 success 95.0% p50 5.0s p95 13.8s $0.0342/success burn 1.0x
last 100 success 70.0% p50 6.6s p95 17.8s $0.0489/success burn 6.0x
errors: {'tool_timeout': 33, 'wrong_result': 12}
page on-call
Compare the first line with the other two. The all-day figures show a mild problem. Split by time, they show a healthy period followed by a severe failure that raised the cost of each successful task. Always be able to cut measures by time, version, tool, model and customer group.
Tokens, latency, cost and errors
Tokens and cost
- Record input, output and cached input tokens separately from the provider's response, because prices usually differ.
- Attribute cost to a task, feature, version and team.
- Include other charges: retrieval, hosted tools, compute and human review time.
- Watch tokens per step. A growing context is a common cause of rising cost.
Store the token counts and calculate money from a versioned price table, so history stays correct when prices change.
Latency
Break the total into queue wait, context building, model time, tool time and approval wait. Show approval wait separately; it is human time and would otherwise hide system slowness.
Errors
Use a small, fixed set of error classes, such as model error, rate limit, tool timeout, invalid arguments, policy refusal, limit stop and wrong result. Free-text messages are for logs. A refusal by policy is not a fault, so chart it apart, but do notice when it jumps.
Questions your data should answer
| Question | Where to look | Likely causes |
|---|---|---|
| Why did cost rise overnight? | Tokens per step, steps per run, volume by feature | Longer tool results, a loop, a new model, more traffic |
| Why is it slow for some users? | Slow-end latency by tool, region and task type | One slow service, large documents, rate limiting |
| Why did success fall after a release? | Success by version and task type; failed traces | Prompt wording, tool description, model behavior |
| Is someone abusing the system? | Spend and refusals by user; unusual destinations | Scripted use, injection attempts |
Try these questions against your telemetry before an incident. Each one you cannot answer names a missing field.
Production dashboards
| Dashboard | Audience | Contents |
|---|---|---|
| Service health | On-call engineer | Objectives, error budget, errors by class, queue age, recent releases |
| Quality | Product and domain owners | Verified success, sampled grades, escalations, corrections |
| Cost | Owners and finance | Spend by feature, cost per success, tokens per step, top consumers |
| Safety | Security and risk | Blocked actions, unusual destinations, access denials, approval patterns |
| Tool health | Integration owners | Calls, errors, latency and rate limits per tool |
Mark releases, prompt changes and model changes on every time chart. Put the target on the chart. Remove panels nobody has used to make a decision.
Service level objectives
A service level indicator is a measurement, such as the share of tasks completed correctly. A service level objective (SLO) is the target for it over a period. The allowed shortfall is the error budget. Google's site reliability engineering book explains the approach.
| Illustrative objective | Window |
|---|---|
| 95% of tasks are verified successful or correctly escalated | 28 days |
| 95% of interactive runs finish within 20 seconds, excluding approval wait | 28 days |
| 99% of accepted background jobs finish within 1 hour | 28 days |
| Cost per successful task stays within the agreed ceiling | 7 days |
Choose targets from what users need and what you can measure, starting from your observed baseline. Do not express a safety rule such as "no unauthorized actions" as a percentage with a budget. Enforce it, and treat any breach as an incident.
Alerting on burn rate
The burn rate says how fast you are using the error budget. A rate of 1 spends exactly the budget over the window; a rate of 6 spends it six times as fast. Alerting when burn is high over both a longer and a shorter window catches serious problems quickly and stops alerting soon after recovery. The program above pages only when both its windows exceed twice the budget rate. Real thresholds and windows depend on your objective and traffic.
| Situation | Response |
|---|---|
| Fast budget burn | Page the on-call person |
| Slow, steady burn | Create a ticket for working hours |
| Safety or access violation | Page immediately, regardless of volume |
| Spend far above forecast | Alert owner; apply a cap if agreed |
| Quality grade drifting down | Review with the product owner |
Every alert needs an owner, a runbook link and an action someone can take. With little traffic, percentages swing wildly, so require a minimum number of events or use synthetic checks.
Error budget arithmetic
With a 95% objective, 5% of tasks may fail within the window. Over 100,000 tasks that is 5,000 failures. If 2,500 have happened a quarter of the way through, half the budget is gone with three quarters of the time left, which calls for attention even if nobody has complained. Agree in advance what a spent budget means, for example pausing risky changes until reliability recovers. An objective with no consequence is only a chart.
Metrics reference
| Metric | Type | Useful labels |
|---|---|---|
| Runs started and ended | Counter | agent, version, end reason |
| Run duration | Histogram | agent, version |
| Model call duration and first-output time | Histogram | model, operation |
| Tokens used | Histogram or counter | model, input or output |
| Tool calls and duration | Counter, histogram | tool, outcome, error class |
| Steps per run | Histogram | agent, version |
| Approvals | Counter, histogram of wait | action type, decision |
| Policy blocks | Counter | rule |
| Queue depth and oldest job age | Gauge | queue |
Never use user ids, run ids or free text as metric labels. Each new value creates a new series and can overwhelm a metrics system. Put identifiers in traces and logs instead.
Standard names
OpenTelemetry publishes semantic conventions for generative AI, marked as in development at the time of writing, so names may still change. Examples include:
| Name | Meaning |
|---|---|
gen_ai.client.token.usage | Metric: tokens used |
gen_ai.client.operation.duration | Metric: duration of a model operation |
gen_ai.operation.name | Attribute: kind of operation, such as chat or execute_tool |
gen_ai.provider.name | Attribute: which provider |
gen_ai.request.model | Attribute: requested model |
gen_ai.agent.name, gen_ai.tool.name | Attributes: which agent and tool |
Following shared names makes it easier to change tools and compare teams. Record which version of the conventions your instrumentation uses.
Reference architecture
- Count metrics for all runs, even when you keep only some traces.
- Keep all traces that failed, were blocked or were very slow or costly, plus a sample of normal ones.
- Decide before launch whether prompts and outputs are stored, who can read them and for how long: see Safe Logging, Sampling and Retention.
- Keep audit records of actions separate from debugging logs, and protect them from change.
- Make sure telemetry failure never stops the agent, and that missing telemetry raises its own alert.
A weekly routine
- Compare objectives and error budget with last week.
- Look at the largest changes in cost per success and steps per task.
- Read ten failed traces and five random successful ones.
- Add recurring failures to the evaluation suite: see Continuous Evaluation, Statistics and Scorecards.
- Remove or fix one noisy alert.
Read some successful traces. Wasted steps, risky near misses and lucky guesses hide inside runs that every dashboard counts as good.
Observability checklist
- Success is defined and measured, not assumed from HTTP status
- Every run has one id across model calls, tools and agents
- Tokens, latency and errors are recorded per step
- Releases and model changes appear on charts
- Objectives have owners and error budgets
- Alerts lead to an action and a runbook
- Sensitive data is redacted and retention is set
Frequently asked questions
Do I need a special agent monitoring product?
Not to start. Structured logs, standard tracing and a dashboard cover much. Specialized tools add trace viewing and evaluation workflows.
Should I store full prompts?
Only with a clear purpose, access control and retention limit. They often contain personal or confidential data.
How do I measure success without ground truth?
Combine system outcomes, user behavior and graded samples, and state the uncertainty.
What should I build first?
A run id, a trace of every step, token and error counts, and one verified outcome measure.
References and further reading
- OpenTelemetry semantic conventions for generative AI
- OpenTelemetry blog on generative AI observability
- Service level objectives (Google SRE book)
Next steps
Agent Tracing and OpenTelemetry
Trace each run.
Debugging Agents, RAG and Handoffs
Find the cause of a failure.
Loops, Performance, Incidents and Maturity
Respond and improve.