-
Notifications
You must be signed in to change notification settings - Fork 868
fix(mcp): remove faulty logic of trying to deduce HTTP errors #3477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe PR refactors MCP instrumentation error handling by removing the unreliable Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important
Looks good to me! 👍
Reviewed everything up to 388f133 in 1 minute and 48 seconds. Click for details.
- Reviewed
320lines of code in1files - Skipped
0files when reviewing. - Skipped posting
4draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/instrumentation.py:293
- Draft comment:
Good fix: Removed the faulty HTTP error deduction (via get_error_type) and regex parsing. This avoids exceptions when non-HTTP numbers appear in error messages. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%<= threshold50%This comment is purely informative, as it praises the fix and explains what was done without providing any actionable feedback or suggestions. It does not align with the rules for useful comments in a pull request review.
2. packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/instrumentation.py:398
- Draft comment:
Removal of the get_error_type function (and its import dependency ‘re’) is appropriate and addresses issue #3474 by eliminating faulty HTTP status deduction. - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
3. packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/instrumentation.py:343
- Draft comment:
Note: In _execute_and_handle_result, if result.isError is true but result.content is empty, no error status is set. Consider if a default error status should be applied in such cases. - Reason this comment was not posted:
Comment was on unchanged code.
4. packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/instrumentation.py:231
- Draft comment:
Using type(e).name for the ERROR_TYPE attribute in exception handling of _fastmcp_client_enter_wrapper improves robustness by avoiding faulty HTTP status mapping. - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
Workflow ID: wflow_Mmi6TQXw0lTcBr9n
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/instrumentation.py (1)
241-267: Unused parameter can be prefixed with underscore.The
tracerparameter is unused in this wrapper method. Consider renaming it to_tracerto indicate it's intentionally unused while maintaining the signature pattern.Apply this diff:
- def _fastmcp_client_exit_wrapper(self, tracer): + def _fastmcp_client_exit_wrapper(self, _tracer): """Wrapper for FastMCP Client.__aexit__ to end the session trace"""
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/instrumentation.py(13 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.py: Store API keys only in environment variables/secure vaults; never hardcode secrets in code
Use Flake8 for code linting and adhere to its rules
Files:
packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/instrumentation.py
🧠 Learnings (1)
📚 Learning: 2025-09-18T14:36:24.693Z
Learnt from: nina-kollman
Repo: traceloop/openllmetry PR: 3388
File: packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/fastmcp_instrumentation.py:20-20
Timestamp: 2025-09-18T14:36:24.693Z
Learning: In packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/fastmcp_instrumentation.py, the team is aware that the global self._server_name field is unsafe for multi-server or concurrent usage but has consciously decided not to support multiple FastMCP servers currently.
Applied to files:
packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/instrumentation.py
🧬 Code graph analysis (1)
packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/instrumentation.py (2)
packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/fastmcp_instrumentation.py (2)
traced_method(51-60)traced_method(65-152)packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/utils.py (1)
dont_throw(12-40)
🪛 Ruff (0.14.6)
packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/instrumentation.py
146-146: Do not catch blind exception: Exception
(BLE001)
151-151: Do not catch blind exception: Exception
(BLE001)
227-227: Do not call setattr with a constant attribute value. It is not any safer than normal property access.
Replace setattr with assignment
(B010)
241-241: Unused method argument: tracer
(ARG002)
257-257: Consider moving this statement to an else block
(TRY300)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Build Packages (3.11)
- GitHub Check: Test Packages (3.10)
- GitHub Check: Test Packages (3.12)
- GitHub Check: Test Packages (3.11)
- GitHub Check: Lint
🔇 Additional comments (5)
packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/instrumentation.py (5)
146-155: LGTM: Exception logging improves debuggability.The addition of warning logs for exceptions in the transport wrapper is helpful for diagnosing instrumentation issues. The broad exception catches are appropriate here since instrumentation should not break the application.
203-209: LGTM: Refactoring improves code organization.Extracting tool call and MCP method handling into separate methods enhances readability and maintainability.
304-306: LGTM: Proper delegation to error handling helper.The call to
_execute_and_handle_resultwithclean_output=Truecorrectly delegates result processing and error handling to the centralized helper method, which resolves the faulty HTTP status code parsing issue.
308-316: LGTM: Consistent error handling for MCP methods.The refactored method correctly delegates to
_execute_and_handle_resultwithclean_output=False, ensuring consistent error handling without attempting to parse HTTP status codes from error messages.
318-355: LGTM: Robust error handling fixes the HTTP status parsing issue.This new helper method properly addresses the bug from issue #3474:
- Uses
type(e).__name__for ERROR_TYPE instead of attempting to parse HTTP status codes from error messages (line 352)- Properly records exceptions and sets error status without brittle number parsing
- Correctly handles both error results (via
isErrorflag) and exceptions- Centralizes result processing logic for maintainability
The fix eliminates the failure mode where numbers like port 443 in error messages would cause
ValueError: 443 is not a valid HTTPStatus.
Fixes #3474
feat(instrumentation): ...orfix(instrumentation): ....Important
Remove faulty logic for deducing HTTP errors in
McpInstrumentorby eliminatingget_error_typefunction and its usage.get_error_typefunction and its usage ininstrumentation.py, which attempted to deduce HTTP errors from error messages.McpInstrumentorclass, specifically in_execute_and_handle_result()andInstrumentedStreamWriter.send().instrumentation.py.This description was created by
for 388f133. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.