learning-it by example

Back to the video

Trace Every Agent Step with OpenTelemetry in Python

Which step of my agent failed, and which was slow? One trace showed both, with the time each step took.

Video #35 ยท AI agents and MCP

Steps in the video

  1. 0:00 Which step failed, and which was slow?
  2. 0:27 The idea
  3. 1:00 Setup
  4. 1:21 Collect the spans
  5. 1:41 Two of the tools
  6. 2:02 A failure on a span
  7. 2:20 The run
  8. 2:32 Read the trace
  9. 3:20 What this does not show
  10. 3:50 Mistakes to avoid
  11. 4:16 My take and next steps
  12. 4:44 Recap

Files

  • agent.py (39 lines)
  • report.py (16 lines)
  • tracing.py (10 lines)

Download the code (zip)

Tested with

Python 3.12.15 | opentelemetry-sdk==1.45.1

What this does not show

The slow step and the failure are staged with a sleep and a raised error. No model call, no collector, no sampling and no network. One trace in one process, timed on Windows, where very short spans are only roughly timed.

Sources

Learning IT by Example.