opentelemetry-instrumentation-genai-openai-agents: handle MCPListToolsSpanData#100
opentelemetry-instrumentation-genai-openai-agents: handle MCPListToolsSpanData#100Jwrede 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
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. |
| GEN_AI_MCP_SERVER_NAME = "gen_ai.mcp.server.name" | ||
| GEN_AI_MCP_TOOL_NAMES = "gen_ai.mcp.tool.names" |
| if operation_name == GenAIOperationName.MCP_LIST_TOOLS: | ||
| return f"{base_name} {tool_name}" if tool_name else base_name |
| 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 PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment. |
| GEN_AI_HANDOFF_TO_AGENT = "gen_ai.handoff.to_agent" | ||
| GEN_AI_EMBEDDINGS_DIMENSION_COUNT = "gen_ai.embeddings.dimension.count" | ||
| GEN_AI_TOKEN_TYPE = _attr("GEN_AI_TOKEN_TYPE", "gen_ai.token.type") | ||
| GEN_AI_MCP_SERVER_NAME = "gen_ai.mcp.server.name" |
There was a problem hiding this comment.
I don't believe these are existing GenAI semantic conventions. This repo implements convention defined in https://github.com/open-telemetry/semantic-conventions-genai. There are some existing operations here that are not following conventions either and they are being removed in the #90.
Please consider modeling this operation using existing conventions or proposing a new one in the https://github.com/open-telemetry/semantic-conventions-genai repo
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