opentelemetry-instrumentation-genai-openai-agents: handle MCPListToolsSpanData#100
Open
Jwrede wants to merge 2 commits into
Open
opentelemetry-instrumentation-genai-openai-agents: handle MCPListToolsSpanData#100Jwrede wants to merge 2 commits into
Jwrede wants to merge 2 commits into
Conversation
MCPListToolsSpanData was not handled in the span processor, causing MCP list_tools spans to show as "unknown" operation. Add handling for this span type with proper operation name (mcp_list_tools), span kind (CLIENT), span naming, and attribute extraction (gen_ai.mcp.server.name, gen_ai.mcp.tool.names). Fixes open-telemetry/opentelemetry-python-contrib#4197 Assisted-by: Claude Opus 4.6
Assisted-by: Claude Opus 4.6
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds first-class support for MCP “list tools” spans so they no longer appear as unknown and instead emit spec-aligned operation names, span names, span kind, and attributes.
Changes:
- Introduces
MCPListToolsSpanDatain test stubs and adds unit tests + lifecycle coverage for MCP list-tools spans. - Extends the span processor to recognize MCP list-tools spans (operation name, span kind, span naming).
- Adds MCP-specific semantic attributes for server name and returned tool names.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| instrumentation/opentelemetry-instrumentation-genai-openai-agents/src/opentelemetry/instrumentation/genai/openai_agents/span_processor.py | Recognize MCP list-tools spans and emit correct operation name, span kind, name, and attributes. |
| instrumentation/opentelemetry-instrumentation-genai-openai-agents/tests/stubs/agents/tracing/init.py | Adds a stub MCPListToolsSpanData type and span type constant used by tests. |
| instrumentation/opentelemetry-instrumentation-genai-openai-agents/tests/test_z_span_processor_unit.py | Adds unit + lifecycle tests for MCP list-tools span naming, kind, and attributes. |
| instrumentation/opentelemetry-instrumentation-genai-openai-agents/.changelog/0.fixed | Documents the fix for MCP list-tools spans previously showing as unknown. |
Comment on lines
+250
to
+251
| GEN_AI_MCP_SERVER_NAME = "gen_ai.mcp.server.name" | ||
| GEN_AI_MCP_TOOL_NAMES = "gen_ai.mcp.tool.names" |
Comment on lines
+431
to
+432
| if operation_name == GenAIOperationName.MCP_LIST_TOOLS: | ||
| return f"{base_name} {tool_name}" if tool_name else base_name |
Comment on lines
+1375
to
+1380
| if _is_instance_of(span.span_data, FunctionSpanData): | ||
| tool_name = getattr(span.span_data, "name", None) | ||
| elif _is_instance_of(span.span_data, MCPListToolsSpanData): | ||
| tool_name = getattr(span.span_data, "server", None) | ||
| else: | ||
| tool_name = None |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Add MCPListToolsSpanData handling to the GenAISemanticProcessor so MCP tool listing spans are reported with proper operation name, span kind, and attributes instead of showing as "unknown" with no data.
Originally submitted as open-telemetry/opentelemetry-python-contrib#4629, closed per maintainer direction to resubmit here.
Fixes open-telemetry/opentelemetry-python-contrib#4197
Type of change
How has this been tested?
All 104 tests pass.
Checklist
Assisted-by: Claude Opus 4.6