Tutorial: Adding Pyroscope Correlation MCP
Objective: Implement tracing.trace_profile_correlator bridging traces and profiles.
Core Idea: Map trace spans to top CPU symbols within overlapping time windows to prioritize optimization efforts.
Workflow:
- Inputs: trace_id, service, profile_type, window
- Fetch trace; derive min/max timestamp
- Query Pyroscope render (from, to) filtered by service + optional trace_id tag
- Convert to pprof; parse top symbols
- For each symbol, heuristically assign to span whose window overlaps largest sample share
- Compute coverage_pct = sum(mapped_symbol_flat / total_flat)
Mapping Heuristic:
- OverlapWeight = durationOverlap(span, symbolTimeRange) * symbolFlat
- Choose span with max OverlapWeight
Output Fields:
- hotspots[] {fn, flat_pct, likely_span}
- coverage_pct
- recommendation
Edge Cases:
- No profile data: hotspots=[]; recommendation references enabling profiling
- Multiple spans same function: attribute to deepest in hierarchy
Security:
- Ensure trace_id validated length/charset to prevent injection in query params
Extensions:
- Add diff baseline capability
- Provide deep link to Pyroscope UI using computed window