Skip to the workspace
Pebellslearn by building
Agent Patterns, Testing and Guardrails  ›  Lesson

Logging, Tracing and Metrics

Structured logging & tracing 12 minStructured logs record each step as searchable fields, traces tie every model and tool call of one run together as timed spans, and a few metrics such as success rate, steps, latency, cost and tool errors show how the agent behaves across many runs.

ai agents / Logging, Tracing and Metrics

Explore each scene at your own pace.

01 · The rule

The rule

Logging, Tracing and Metrics

Asha complains: "Tripmate took two minutes and then said no trains exist." In a normal program you would open the logs and see the error. In an agent, the answer is hidden in a chain of model calls and tool calls that happened once and will never repeat exactly. If you did not record that chain, you cannot explain it.

The rule

Record every step as structured data, and watch a few numbers that matter.

Structured logging means each event is recorded as fields, not a free-text sentence, so it can be searched and counted:

{"run_id": "r-8841", "step": 3, "type": "tool_call", "tool": "search_trains",
 "args": {"from": "PUNE", "to": "JP", "date": "2026-10-16"},
 "status": "error", "error": "timeout", "ms": 30000, "input_tokens": 6120}

A trace ties all the events of one run together: every model call and tool call becomes a timed span, nested under the request that caused it. Reading a trace is like replaying the run: what the model saw, what it asked for, what came back, how long each step took, and what it cost.

Metrics summarise many runs. A small, steady set covers most needs:

  • Task success rate — share of runs that achieved the user's goal.
  • Steps per task — rising numbers often mean the agent is wandering.
  • Latency — time to the final answer.
  • Cost per task — tokens and money, ideally per successful task.
  • Tool error rate — per tool, so a failing integration stands out.
  • Escalation rate — how often the agent had to hand over to a person.

Logs hold user data, so apply the same care as anywhere else: redact personal details such as phone numbers, and keep logs only as long as you need them.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.