fix: record JSON-RPC errors on client OpenTelemetry spans - #3247
Open
jstar0 wants to merge 1 commit into
Open
Conversation
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
Fixes #3174.
When the MCP peer returns a JSON-RPC error,
send_raw_request()receives theErrorDatawhile the client OpenTelemetry span is active, but the span closesbefore that response is converted to
MCPError. Failed requests therefore looklike normal exits in client telemetry.
Changes
This change:
StatusCode.ERROR, the JSON-RPC message,error.type, andrpc.response.status_codeon the active client span;ErrorDatatoMCPErrorconversion and its publicexception contract; and
The scope is limited to client telemetry. Wire messages, request correlation,
timeouts, cancellation, connection-close handling, and handler exception
behavior are unchanged.
Verification
./scripts/test(5581 passed, 10 skipped, 1 xfailed; 100% coverage)uv run --frozen ruff check src/mcp/shared/jsonrpc_dispatcher.py tests/server/test_otel.pyuv run --frozen ruff format --check src/mcp/shared/jsonrpc_dispatcher.py tests/server/test_otel.pyuv run --frozen pyright src/mcp/shared/jsonrpc_dispatcher.py tests/server/test_otel.pyThe changed files pass Pyright. A full macOS Pyright run also reports two
pre-existing
os.waitidtyping errors intests/transports/stdio/test_lifecycle.py:234, which is outside this diff.AI assistance was used to help analyze and implement this change; I reviewed
the source and tests, reran the reproduction and verification, and take
responsibility for the contribution.