[DNM] OTEL: Instrument all MCP methods#3890
Draft
strawgate wants to merge 4 commits intoPrefectHQ:mainfrom
Draft
[DNM] OTEL: Instrument all MCP methods#3890strawgate wants to merge 4 commits intoPrefectHQ:mainfrom
strawgate wants to merge 4 commits intoPrefectHQ:mainfrom
Conversation
- Add server_span wrappers to list_tools, list_resources, list_resource_templates, and list_prompts in FastMCP server - Add client_span wrappers to list_tools_mcp, list_resources_mcp, list_resource_templates_mcp, and list_prompts_mcp in client mixins - Add optional `method` parameter to delegate_span in telemetry.py and set mcp.method.name on delegate spans - Update all delegate_span callers in fastmcp_provider.py to pass the MCP method name (tools/call, resources/read, prompts/get) - Add tests for new server list spans, client list spans, and delegate span method attributes Refs: PrefectHQ#3887 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Test Failure AnalysisSummary: The Root Cause: Two files were reformatted by
Suggested Solution: Run uv run ruff format src/fastmcp/server/server.py tests/client/telemetry/test_client_list_tracing.pyOr run the full pre-commit suite to catch all issues at once: uv run prek run --all-filesThen commit and push the reformatted files. Detailed AnalysisThe Diff applied by ruff in @@ -621,9 +621,7 @@
# Core logic: list tools
- with server_span(
- "tools/list", "tools/list", self.name, "tool", ""
- ):
+ with server_span("tools/list", "tools/list", self.name, "tool", ""):
@@ -1028,9 +1026,7 @@
# Core logic: list prompts
- with server_span(
- "prompts/list", "prompts/list", self.name, "prompt", ""
- ):
+ with server_span("prompts/list", "prompts/list", self.name, "prompt", ""):Diff applied by ruff in @@ -70,8 +70,7 @@
(
s
for s in tools_list_spans
- if s.attributes is not None
- and "fastmcp.server.name" in s.attributes
+ if s.attributes is not None and "fastmcp.server.name" in s.attributes
),
Related Files
|
Move server_span() inside the else branch (after middleware check) for list_tools, list_resources, list_resource_templates, and list_prompts, matching the existing pattern in call_tool/read_resource/render_prompt. Fix 2-space indentation to 4-space to match the rest of the file. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2 tasks
Wrap attribute-setting blocks in server_span, delegate_span, and client_span with `if span.is_recording():` to avoid unnecessary work on non-recording spans. Add error.type attribute using `type(e).__qualname__` for proper exception class identification. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Adds OpenTelemetry span coverage for MCP list operations and enriches delegate spans with method names. Refs #3887.
list_tools,list_resources,list_resource_templates, andlist_promptsinserver_span()insrc/fastmcp/server/server.pylist_tools_mcp,list_resources_mcp,list_resource_templates_mcp, andlist_prompts_mcpinclient_span()in client mixinsmcp.method.nameon delegate spans: Adds optionalmethodparameter todelegate_span()insrc/fastmcp/server/telemetry.pyand propagates the MCP method name from all callers insrc/fastmcp/server/providers/fastmcp_provider.pyTest plan
uv run ruff check src/passesuv run pytest tests/server/telemetry tests/client/telemetry -x-- all 46 tests pass (18 new + 28 existing)🤖 Generated with Claude Code