Phase 13: Tools & Protocols

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. 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. A debug from February 2026: user reports "my agent sometimes takes 30 seconds to respond; other times 3 seconds." No traces. Logs show the LLM call, but not the tool dispatch, not the MCP server round-trip, not the sub-agent. You guess. Eventually you find: one MCP server occasionally hangs on a cold-start. Without end-to-end tracing, you cannot find this. OTel GenAI fixes it. The conventions settled in 2025-2026 under the OpenTelemetry semantic-conventions group. They define stable attribute names so Datadog, Langfuse, Phoenix, OpenLLMetry, and AgentOps all parse the same spans. Instrument once; ship to any backend. The…

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.…

This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.

Browse the complete course catalog or open this lesson on GitHub.