OpenTelemetry GenAI — Tracing Tool Calls End-to-End

An agent calls five tools, three MCP servers, and two sub-agents. You need one trace across all of it. The OpenTelemetry GenAI semantic conventions (stable attributes in v1.37 and up) are the 2026 standard, natively supported by Datadog, Langfuse, Arize Phoenix, OpenLLMetry, and AgentOps. This lesson names the required attributes, walks the span hierarchy (agent → LLM → tool), and ships a stdlib span emitter you can plug into any OTel exporter.

Build 1.3 hr Python (stdlib, OTel span emitter)

Prerequisites: Phase 13 · 07 (MCP server), Phase 13 · 08 (MCP client)

#Learning Objectives

  • Name the required OTel GenAI attributes for an LLM span and a tool-execution span.
  • Build a trace hierarchy that covers agent loop, LLM call, tool call, and MCP client dispatch.
  • Decide what content to capture (opt-in) vs redact (defaults).
  • Emit spans to a local collector (Jaeger, Langfuse) without rewriting tool code.
Full Access lesson

Keep going. The rest of this lesson is one step away.

Unlock all 503 lessons, video, code, quizzes and every future update. Pay in your own currency with Paystack.

The text and code of this lesson are based on AI Engineering from Scratch by Rohit Ghumare, MIT licensed.