Tutorial: Building a Trace Summarizer MCP
Objective: Implement tracing.trace_summarizer to convert raw trace data into actionable latency narrative.
Steps:
- Define JSON Schema (inputs/outputs) ensuring required: trace_id
- Implement client for Tempo/Jaeger gRPC or HTTP
- Parse spans -> build parent/child edges
- Compute exclusive duration: exclusive = span.duration - sum(child.durations overlapping)
- Rank top N spans by exclusive_ms
- Detect errors: status != OK or events containing exception
- Generate narrative template (critical span + % of total)
Example Go Skeleton:
// pseudo
trace := fetchTrace(ctx, traceID)
root := buildTree(trace.Spans)
calcExclusive(root)
critical := rankExclusive(root, 5)
errors := collectErrors(root)
summary := renderNarrative(critical, errors)
Edge Cases:
- Orphan spans: attach to synthetic root
- Large traces > max_spans: truncate & warn
Testing:
- Use fixture trace with known critical path; assert exclusive ordering
- Inject error span; ensure detection
Hardening:
- Add timeout + circuit breaker
- Limit output size (cap spans_total)
Extension Path:
- Add CPU vs wall correlation (needs profiling tags)