fix: align MCP span naming and metric buckets with OTel MCP semantic conventions#268
Merged
adityamehra merged 3 commits intomainfrom Apr 16, 2026
Merged
fix: align MCP span naming and metric buckets with OTel MCP semantic conventions#268adityamehra merged 3 commits intomainfrom
adityamehra merged 3 commits intomainfrom
Conversation
…conventions
MCPToolCall spans now use {mcp.method.name} {tool_name} format (e.g.
"tools/call add") with CLIENT/SERVER SpanKind, matching the OTel MCP
semconv spec. Previously used "execute_tool {tool_name}" with INTERNAL.
Added explicit bucket boundaries [0.01..300] to all MCP duration
histograms per semconv specification.
Made-with: Cursor
Open
7 tasks
etserend
approved these changes
Apr 15, 2026
shuningc
reviewed
Apr 15, 2026
| @@ -783,8 +784,14 @@ def _start_tool_call(self, tool: ToolCall) -> None: | |||
| Span name: execute_tool {gen_ai.tool.name} | |||
Contributor
There was a problem hiding this comment.
It could be clearer to mention this span name only applies to non MCP tool calls
Contributor
Author
There was a problem hiding this comment.
Pls see below lines for the comment -
MCPToolCall instances are dispatched to _start_mcp_tool_call for
MCP semconv span naming ({mcp.method.name} {target}) and SpanKind.
wrisa
approved these changes
Apr 15, 2026
| """ | ||
| # Span name per semconv: "execute_tool {gen_ai.tool.name}" | ||
| if isinstance(tool, MCPToolCall): | ||
| self._start_mcp_tool_call(tool) |
Contributor
There was a problem hiding this comment.
Why duplicate logic for span creation in this method ? Can we just have separate logic for name and kind here for mcp tools?
Contributor
Author
There was a problem hiding this comment.
Forgot to explicitly mention it to the coding agent to follow DRY. I will clean it in the next PR
Resolve conflict in instruments.py: keep both MCP operation duration buckets (from this branch) and evaluation cost buckets (from main). Made-with: Cursor
…naming Made-with: Cursor # Conflicts: # util/opentelemetry-util-genai/src/opentelemetry/util/genai/instruments.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MCPToolCallspans now use{mcp.method.name} {tool_name}format (e.g.tools/call add) instead ofexecute_tool {tool_name}, matching the OTel MCP semantic conventionsCLIENTfor client-side,SERVERfor server-side (wasINTERNAL)[0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 30, 60, 120, 300]Sample span output
From
dev_assistant_client.py --console(client-sidecall_toolspan):{ "name": "tools/call get_system_info", "kind": "SpanKind.CLIENT", "parent_id": "0x9b8290b6d8c0f51b", "status": { "status_code": "UNSET" }, "attributes": { "gen_ai.operation.name": "execute_tool", "gen_ai.provider.name": "mcp", "gen_ai.agent.name": "mcp.client", "gen_ai.tool.name": "get_system_info", "gen_ai.tool.call.id": "312fadba-c1b5-46e5-b984-10440d7ffd6f", "gen_ai.tool.type": "extension", "mcp.method.name": "tools/call", "network.transport": "pipe" } }Before (old span naming):
After (MCP semconv aligned):
Test plan
make lintpasses (no new issues in changed files)pytest util/opentelemetry-util-genai/tests/-- 181 passedpytest instrumentation-genai/opentelemetry-instrumentation-fastmcp/tests/-- 74 passeddev_assistant_client.py --consolesmoke test confirmstools/call {name}spans withSpanKind.CLIENTexecute_tool {name}/INTERNAL)