Skip to content

opentelemetry-instrumentation-genai-openai-agents: handle MCPListToolsSpanData#100

Open
Jwrede wants to merge 2 commits into
open-telemetry:mainfrom
Jwrede:fix/mcp-list-tools-span-data
Open

opentelemetry-instrumentation-genai-openai-agents: handle MCPListToolsSpanData#100
Jwrede wants to merge 2 commits into
open-telemetry:mainfrom
Jwrede:fix/mcp-list-tools-span-data

Conversation

@Jwrede
Copy link
Copy Markdown
Contributor

@Jwrede Jwrede commented May 30, 2026

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

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

  • Unit tests for operation name, span kind, span naming, and attribute extraction (with/without server name, with/without tool results)
  • Full span lifecycle test

All 104 tests pass.

Checklist

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

Assisted-by: Claude Opus 4.6

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
Copilot AI review requested due to automatic review settings May 30, 2026 12:44
@Jwrede Jwrede requested a review from a team as a code owner May 30, 2026 12:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MCPListToolsSpanData in 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[OpenAI Agents] MCP List Tools spans show only as "unknown" with no data

2 participants