Lesson 11.06 · Phase 11 · Evaluation & Observability

Tracing with OpenTelemetry

A trace is the agent's run as a tree. One span for the agent, children for every model call and tool call, grandchildren in the services those tools call, all sharing one trace ID. OpenTelemetry standardises the shape, and its GenAI semantic conventions standardise the names (genai.request.model, genai.usage.inputtokens, genai.tool.name), so any backend can read your agent's traces. Build the data model by hand, then swap in the real SDK in 30 lines.

Learning objectives

  • Implement spans with trace, span and parent IDs, and a context that follows the call stack.
  • Instrument an agent with GenAI semantic-convention attributes for agent, model and tool spans.
  • Propagate a trace into another service with the W3C traceparent header, and record errors as span status.
  • Export spans in the OTLP JSON shape, and run the same instrumentation on the real OpenTelemetry SDK.

A user reports "the agent said it couldn't find the price". Your logs have a line per model call and a line per tool call, from three processes, interleaved with other users' requests. Which tool call belonged to that conversation? Did the price service fail, or did the agent pass it a bad argument? How many tokens did the whole run cost?

Loading the full lesson…