Chapter 23: Observability
Lecture
Chapter principle
Key takeaways
- Logging records events; tracing preserves causal relationships.
- Trace meaningful actions and decisions, not hidden chain-of-thought.
- Keep nested agents, retries, state mutations and fallbacks visible.
- Distinguish inclusive from exclusive cost.
- Parallel latency follows the critical path; percentiles beat averages.
- Metrics summarize populations; traces diagnose individual executions.
Experiments
Every experiment in the book is small, runnable and printed with its real output. In the Lab you can replay a recorded real run of each one, with no programming, and watch what the model and the agent do.
Experiment 41: Tracing an agent run
How do you see which step caused which work?
A real model gets a task: find the price of product X, then add 10%. It can use two tools: a price lookup and a calculator. While the agent works, a tracer records each piece of work as a span: a named step with its duration, its details, and a link to the step that started it. At the end the spans are printed twice: as a tree that follows those links, and as a flat list without them. This is a recorded run of a real model; the times will differ in a new run.
Experiment 42: Adding up cost and time
How much did a run really cost, and what made it slow?
The program makes three real model calls of very different length: a one-word answer, a 40-word answer and a 150-word answer. It times each call and counts its tokens, which serve as the measure of cost because prices change. First it runs the three one after another under a whole-run span that records the total; then it sends all three at the same time. This is a recorded run of a real model; times and tokens will differ in a new run.
All the code for this chapter: github.com/agentic-engineering-book/code
Download the bookBrowse all chapters