Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 9, 2026

Phase 3: Implement get_critical_path Tool (Tool #4)

Part of #7827

Summary

This PR implements the get_critical_path MCP tool as part of Phase 3 of the Jaeger MCP server implementation. The tool identifies the sequence of spans forming the critical latency path (the blocking execution path) in a distributed trace.

Implementation Details

  1. Critical Path Algorithm (Port from UI)

    • Ported the critical path computation algorithm from TypeScript (jaeger-ui) to Go
    • Implements recursive algorithm to find Last Finishing Child (LFC) spans
    • Handles edge cases like overflowing child spans and FOLLOWS_FROM relationships
    • Includes comprehensive unit tests matching UI test cases
  2. MCP Tool Handler

    • Created get_critical_path tool handler that:
      • Accepts trace ID as input
      • Fetches trace data via QueryService
      • Computes critical path using the ported algorithm
      • Returns formatted output with span details, service names, and timing information
    • Includes proper error handling and input validation
  3. Integration

    • Registered tool in MCP server
    • Defined JSON schemas for input/output types
    • Connected handler to QueryService from jaegerquery extension

Testing & Coverage

  • ✅ All unit tests passing
  • criticalpath package: 95.9% coverage
  • handlers package: 96.4% coverage
  • ✅ Comprehensive test cases including edge cases
  • make fmt passes
  • make lint passes with 0 issues
  • make test passes (for jaegermcp package)

Changes

  • Created internal/criticalpath/ package with algorithm implementation
  • Created internal/handlers/ package with tool handlers
  • Created internal/types/ package with MCP tool types
  • Updated MCP server to register the new tool
  • Updated README with current implementation status
  • Added comprehensive tests achieving >95% code coverage
Original prompt

implement phase 3 step 4 from ADR 002 as part of issue #7827. State Part of #7827 in PR description. Run make fmt make lint and make test to success everytime before pushing to remove branch.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@yurishkuro yurishkuro changed the title [WIP] Implement phase 3 step 4 from ADR 002 [mcp] Phase 3 step 4: trace search Jan 9, 2026
@yurishkuro yurishkuro added the changelog:experimental Change to an experimental part of the code label Jan 9, 2026
@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 50.90253% with 136 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.67%. Comparing base (55fbe8c) to head (649de18).

Files with missing lines Patch % Lines
...n/jaegermcp/internal/handlers/get_critical_path.go 0.00% 74 Missing ⚠️
...ension/jaegermcp/internal/criticalpath/sanitize.go 41.07% 30 Missing and 3 partials ⚠️
...germcp/internal/criticalpath/get_child_of_spans.go 36.00% 13 Missing and 3 partials ⚠️
...on/jaegermcp/internal/criticalpath/criticalpath.go 86.44% 4 Missing and 4 partials ⚠️
cmd/jaeger/internal/extension/jaegermcp/server.go 57.14% 3 Missing ⚠️
...ension/jaegermcp/internal/criticalpath/find_lfc.go 90.00% 1 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (50.90%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project check has failed because the head coverage (94.67%) is below the target coverage (95.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7857      +/-   ##
==========================================
- Coverage   95.46%   94.67%   -0.79%     
==========================================
  Files         300      306       +6     
  Lines       15731    16008     +277     
==========================================
+ Hits        15017    15156     +139     
- Misses        560      686     +126     
- Partials      154      166      +12     
Flag Coverage Δ
badger_v1 9.18% <ø> (ø)
badger_v2 1.93% <ø> (ø)
cassandra-4.x-v1-manual 13.58% <ø> (ø)
cassandra-4.x-v2-auto 1.92% <ø> (ø)
cassandra-4.x-v2-manual 1.92% <ø> (ø)
cassandra-5.x-v1-manual 13.58% <ø> (ø)
cassandra-5.x-v2-auto 1.92% <ø> (ø)
cassandra-5.x-v2-manual 1.92% <ø> (ø)
clickhouse 1.97% <ø> (ø)
elasticsearch-6.x-v1 17.54% <ø> (ø)
elasticsearch-7.x-v1 17.57% <ø> (ø)
elasticsearch-8.x-v1 17.72% <ø> (ø)
elasticsearch-8.x-v2 1.93% <ø> (ø)
elasticsearch-9.x-v2 1.93% <ø> (ø)
grpc_v1 8.84% <ø> (ø)
grpc_v2 1.93% <ø> (ø)
kafka-3.x-v2 1.93% <ø> (ø)
memory_v2 1.93% <ø> (ø)
opensearch-1.x-v1 17.61% <ø> (ø)
opensearch-2.x-v1 17.61% <ø> (ø)
opensearch-2.x-v2 1.93% <ø> (ø)
opensearch-3.x-v2 1.93% <ø> (ø)
query 1.93% <ø> (ø)
tailsampling-processor 0.55% <ø> (ø)
unittests 93.31% <50.90%> (-0.76%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI and others added 3 commits January 9, 2026 21:54
Co-authored-by: yurishkuro <3523016+yurishkuro@users.noreply.github.com>
Co-authored-by: yurishkuro <3523016+yurishkuro@users.noreply.github.com>
Co-authored-by: yurishkuro <3523016+yurishkuro@users.noreply.github.com>
Copilot AI changed the title [mcp] Phase 3 step 4: trace search [mcp] Implement get_critical_path tool (Phase 3 Step 4) Jan 9, 2026
Copilot AI requested a review from yurishkuro January 9, 2026 21:59
@yurishkuro
Copy link
Member

@copilot Make sure all new code has good test coverage, no less than 95%.

- Added tests for getChildOfSpans function with 100% coverage
- Added tests for sanitizeOverFlowingChildren with 96.2% coverage
- Added tests for get_critical_path handler with 96.4% coverage
- Refactored handler to use TraceGetter interface for better testability
- Fixed testifylint issues
- All packages now have >95% test coverage

Co-authored-by: yurishkuro <3523016+yurishkuro@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 10, 2026

@copilot Make sure all new code has good test coverage, no less than 95%.

Done. Added comprehensive tests achieving >95% coverage for all new code:

  • criticalpath package: 95.9% coverage
  • handlers package: 96.4% coverage

Commit: eb49c13

Signed-off-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:experimental Change to an experimental part of the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants