Trace a Tool Call End to End
Follow one request across the whole stack.
Trace a Tool Call End to End is a free MCP Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MCP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Following One Call
A single tool call may touch your server, a database, and an API. Tracing stitches those hops into one timeline so you see the whole journey. 🧵
Traces and Spans
A trace is the full request; a span is one step inside it. Each span records a name, a start, and a duration, and spans nest like a tree.
The Trace ID
Every span in one request shares a single trace ID. That shared id is what lets a tool reconstruct exactly which steps belonged together.
Parent and Child Spans
Spans link through a parent ID. The tool call is the parent; the database query and API call become its children, forming the timeline tree.
OpenTelemetry
The standard for this in Python is OpenTelemetry. It defines traces, spans, and context so your data works with many backends, not just one.
Start a Span
You wrap work in a span using a context manager. Everything inside it is timed and nested under the current trace automatically.
from opentelemetry import trace
tracer = trace.get_tracer("mcp")
with tracer.start_as_current_span("search_tool"):
run_search()Add Attributes
Decorate a span with attributes: small key-value facts like the tool name or result count. They make a trace far easier to read later.
span = trace.get_current_span()
span.set_attribute("tool.name", "search")
span.set_attribute("result.count", 3)Spans Catch Errors
When a step fails, mark its span with the error status. The trace then shows you exactly which hop broke the request, not just that it broke.
Context Propagation
To trace across a network call, you pass the trace context along in headers. This propagation keeps the remote step under the same trace.
Link Logs to Traces
Put the trace ID into your structured logs too. Now a log line and its full trace point at each other, and debugging gets dramatically faster.
Exporting Traces
Spans are sent to a backend through an exporter, often via the OTLP protocol. The backend then draws the timeline you click through.
Quick Check
Let us confirm the trace structure.
Recap
You can now trace a call end to end with spans under one trace ID, enriched with attributes, error status, and logs that link straight back. 🗺️
Frequently asked questions
Is the “Trace a Tool Call End to End” lesson free?
Yes — the full text of “Trace a Tool Call End to End” is free to read here on the web, and the MCP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MCP Academy course, upgrade to CoddyKit PRO.
What will I learn in “Trace a Tool Call End to End”?
Follow one request across the whole stack. You practise MCP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start MCP Academy?
No prior experience is required. MCP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Trace a Tool Call End to End” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this MCP Academy lesson?
Yes. Every MCP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- What to Measure in a Server
- Structured Logs You Can Search
- Trace a Tool Call End to End
- Alert on Failures & Abuse