Applicability
When to Use
✓When requests involve multiple MCP servers
✓When you need to identify performance bottlenecks
✓When debugging complex multi-service workflows
Overview
How It Works
Distributed tracing creates a trace for each user request and adds spans for each MCP server call within that request. Spans include timing, status, and parent-child relationships, allowing you to visualize the entire request flow as a waterfall diagram.
The agent creates a root span for each request and passes the trace context to each MCP server call. Child spans are created for each tool invocation, and the complete trace is exported to Jaeger or a similar tracing backend.
Implementation
Code Example
typescript
async function tracedRequest(requestId, handler) {
const trace = { id: requestId, spans: [], startTime: Date.now() };
const tracedCall = async (server, tool, args) => {
const span = { server, tool, startTime: Date.now(), parentId: requestId };
try {
const result = await mcpServers[server][tool](args);
span.duration = Date.now() - span.startTime;
span.status = "ok";
trace.spans.push(span);
return result;
} catch (error) {
span.duration = Date.now() - span.startTime;
span.status = "error";
span.error = error.message;
trace.spans.push(span);
throw error;
}
};
const result = await handler(tracedCall);
trace.duration = Date.now() - trace.startTime;
await jaeger.reportTrace(trace);
return result;
}Quick Info
Categorymonitoring
ComplexityHard