Skip to content

Add mcp.server.operation.duration metric per OTEL MCP semantic conventions - #3752

Merged
ChrisJBurns merged 1 commit into
mainfrom
otel/add-standard-metrics
Feb 10, 2026
Merged

ChrisJBurns merged 1 commit into
mainfrom
otel/add-standard-metrics

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Feb 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Adds the mcp.server.operation.duration histogram metric as defined by the OTEL MCP semantic conventions
  • Records operation latency with spec-defined attributes: mcp.method.name, gen_ai.tool.name, gen_ai.operation.name, gen_ai.prompt.name, jsonrpc.protocol.version, network.transport, network.protocol.name, network.protocol.version, error.type
  • Exports MCPHistogramBuckets for reuse by future metrics (e.g. mcp.server.session.duration)
  • Adds warning log when MCP method cannot be determined (indicates middleware misconfiguration)
  • Existing custom toolhive_mcp_* metrics are preserved for backward compatibility

Note: mcp.server.session.duration is intentionally deferred — it will be trivial to add after the session management architecture refactor (#38).

Test plan

  • TestHTTPMiddleware_OperationDuration/tools/call — verifies metric recorded with tool attributes
  • TestHTTPMiddleware_OperationDuration/prompts/get — verifies metric recorded with prompt attributes
  • TestHTTPMiddleware_OperationDuration/non-MCP — verifies metric is NOT recorded for non-MCP requests
  • task lint-fix passes with 0 issues
  • task test passes

🤖 Generated with Claude Code

@github-actions github-actions Bot added the size/M Medium PR: 300-599 lines changed label Feb 10, 2026
@codecov

codecov Bot commented Feb 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.39%. Comparing base (9405bac) to head (42eafe8).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/telemetry/middleware.go 93.75% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3752      +/-   ##
==========================================
+ Coverage   66.36%   66.39%   +0.02%     
==========================================
  Files         427      427              
  Lines       41894    41926      +32     
==========================================
+ Hits        27803    27835      +32     
+ Misses      11976    11974       -2     
- Partials     2115     2117       +2     

☔ 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.

@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed size/L Large PR: 600-999 lines changed labels Feb 10, 2026
@ChrisJBurns
ChrisJBurns force-pushed the otel/add-standard-metrics branch from 539e0a4 to 23f00b3 Compare February 10, 2026 20:14
@github-actions github-actions Bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Feb 10, 2026
@ChrisJBurns
ChrisJBurns force-pushed the otel/add-standard-metrics branch from 23f00b3 to d187fa8 Compare February 10, 2026 20:22
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/M Medium PR: 300-599 lines changed labels Feb 10, 2026
@ChrisJBurns ChrisJBurns changed the title DRAFT: Add OTEL MCP spec metrics for operation and session duration Add OTEL MCP spec metrics for operation and session duration Feb 10, 2026
Comment thread pkg/telemetry/middleware.go Resolved
Comment thread pkg/telemetry/middleware.go Resolved
Comment thread pkg/transport/session/manager.go Resolved
…tions

Implement the mcp.server.operation.duration histogram metric as defined
by the OTEL MCP semantic conventions. This records operation latency with
spec-defined attributes (mcp.method.name, gen_ai.tool.name,
gen_ai.operation.name, gen_ai.prompt.name, jsonrpc.protocol.version,
network.transport, network.protocol.name, network.protocol.version,
error.type) alongside existing custom toolhive_mcp_* metrics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ChrisJBurns
ChrisJBurns force-pushed the otel/add-standard-metrics branch from d187fa8 to 42eafe8 Compare February 10, 2026 21:51
@ChrisJBurns ChrisJBurns changed the title Add OTEL MCP spec metrics for operation and session duration Add mcp.server.operation.duration metric per OTEL MCP semantic conventions Feb 10, 2026
@github-actions github-actions Bot added size/S Small PR: 100-299 lines changed and removed size/L Large PR: 600-999 lines changed labels Feb 10, 2026
@ChrisJBurns ChrisJBurns changed the title Add mcp.server.operation.duration metric per OTEL MCP semantic conventions Add mcp.server.operation.duration metric per OTEL MCP semantic conventions Feb 10, 2026
@ChrisJBurns
ChrisJBurns merged commit 9f28499 into main Feb 10, 2026
60 of 61 checks passed
@ChrisJBurns
ChrisJBurns deleted the otel/add-standard-metrics branch February 10, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants