Lesson 00.07 · Phase 00 · Setup & Tooling

Tracing from day one

You can't debug step 38 of an agent run from its final answer. Record every model call and tool call as a span from the very first line of code, and every later phase of this course gets easier.

Learning objectives

  • Explain traces and spans, and why agents need them more than ordinary web services.
  • Build a tracer with nested spans that stays correct across threads and asyncio tasks, using contextvars.
  • Record model and tool calls with OpenTelemetry's GenAI attribute names (genai.), so traces port to real tools later.
  • Export traces as JSONL, scrub secrets, and render a waterfall that shows where the time and tokens went.

An agent answers a support question wrongly. Was it the model, the retrieval, or a tool that failed and got papered over? The final answer can't tell you. And agent runs are long: a coding agent can make 50+ model calls and 100+ tool calls for one task. print() debugging doesn't scale to that, and adding logging after something goes wrong in production is too late, because that run is gone.

Loading the full lesson…