Repository navigation
Conversation
|
@RealAdhi On the open question, I think the span should keep the plain |
|
@girishkvs Good catch. I'd only looked at |
sivaraman-krishnan
left a comment
There was a problem hiding this comment.
Thanks, @RealAdhi! I checked that the status description was the only place the SDK put these messages on spans: AddExceptionTags doesn't record exception events or exception.* tags, so with this change only McpException messages still reach the span, as intended.
One more client-side effect that might be worth adding to the description: local HTTP transport failures. When a POST fails, the HTTP transports throw an HttpRequestException whose message includes the response body when available. Streamable HTTP does this unless it turns the response into an McpProtocolException, and truncates the body via CreateHttpRequestExceptionWithBodyAsync. SSE does it for any non-success status and includes the full body via CreateHttpRequestException. That exception reaches AddExceptionTags unwrapped through SendRequestAsync, so before this change the response body could end up in the client span's status description. Now there is no description and error.type is System.Net.Http.HttpRequestException. That seems like the right outcome for the same reason. The PR description doesn't mention HTTP transport failures, though, and the test doesn't cover this path.
…t span status HTTP client transports throw HttpRequestException with the response body in the message when a POST fails. Add a test that a failing send surfaces as an error span with no status description and error.type set to the exception type. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AkKv99L5HA4BBrocAW75Qe
Fixes #2060
Problem
On the server, a normal exception reaches the client only as "An error occurred.", but the span was recording the real exception message. So the trace leaked more than the client ever saw.
In
McpSessionHandler:AddResponseTagsset the span status description tocontent.ToJsonString()for any result withisError: true, putting tool result content into traces.AddExceptionTagsset it toe.Messagefor every exception.Change
isErrorresults:SetStatus(ActivityStatusCode.Error)with no description.error.type=tool_erroralready marks the failure.McpExceptionmessages (includingMcpProtocolException) are kept, since the server sends that message as the JSON-RPC error message the peer already sees, per the semconv guidance that the status description SHOULD matchJSONRPCError.message. Other exception messages are dropped.error.typeand status-code tags are unchanged.Since both helpers are shared, client spans for
isErrorresults also lose their description. Client-side remote errors areMcpProtocolExceptions, so client spans still keep a description for those.Tests
Session_ErrorStatusDescription_DoesNotContainToolContentOrExceptionMessagetoDiagnosticTests.cs(a tool returning anisErrorresult, a handler that throwsInvalidOperationException, and one that throwsMcpException). It fails before the change (Actual: "[{\"type\":\"text\",\"text\":\"secret tool content"···, then"secret exception message") and passes after.dotnet build: 0 warnings, 0 errors.ModelContextProtocol.Testspasses on net10.0, net9.0, net8.0 and net472.ServerConformanceTestsin AspNetCore.Tests fail identically with and without this change on my machine (pre-existing, environment-related).AI disclosure: I used an AI coding assistant to help write this change; I reviewed every line, ran the suite locally, and can explain it.
Local HTTP transport failures
HTTP client transports throw
HttpRequestExceptionwith the response body in the message when a POST fails (the SSE transport includes the full body; Streamable HTTP truncates it). That exception reachesAddExceptionTagsunwrapped. It is not anMcpException, so the span now gets no status description, anderror.typeisSystem.Net.Http.HttpRequestException. This path is covered bySession_HttpTransportFailure_DoesNotCopyResponseBodyIntoClientSpanStatus.Generated by Claude Code