Repository navigation
feat(http): trace tool calls to Sentry - #246
Conversation
Sentry's MCP dashboard stays empty because the server sends only errors. Each tools/call now runs in a root transaction named `tools/call <tool>` with op `mcp.server`, carrying the tool, client, transport and whether the result was an error. Tracing is off unless SOCKET_MCP_SENTRY_TRACES_SAMPLE_RATE is set above 0 with the DSN. Transactions are rebuilt from an allowlist before they leave the process, like error events: no child spans, arguments, results, headers, user data or tags. A client named only by its User-Agent is now tagged with the same client family the hosted proxy uses (`claude-code`, `cursor`, `curl`, or `other`), so both layers name a client the same way.
PR SummaryMedium Risk Overview The Client tagging when Reviewed by Cursor Bugbot for commit 523c96f. Configure here. |
Tools report most failures as an error result rather than throwing, so those transactions ended with an ok status and Sentry's failure rate counted them as successes. A call whose outcome is not success now gets error.type tool_error and the internal_error status, as Sentry's own MCP integration does.
With SOCKET_MCP_SENTRY_TRACES_SAMPLE_RATE unset or 0, the reporter no longer installs Sentry's global client and tool calls run without a span wrapper, so errors-only deployments behave as before tracing.
|
bugbot review |
John-David Dalton (jdalton)
left a comment
There was a problem hiding this comment.
[agent] The failed-call status and rate-zero changes address the earlier feedback. The remaining test gap is overlapping HTTP requests, where Sentry’s shared scope matters.
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 523c96f. Configure here.
The trace test only covered back-to-back calls and passed if one trace id was missing. It now checks both are valid root traces, and a new case holds one call open upstream while another finishes. The tracing docs now split setup from what Sentry shows.
Sentry's MCP dashboard is empty because socket-mcp sends only errors (#243). Each
tools/callnow runs in a root transaction that the dashboard reads. Tracing is off unlessSOCKET_MCP_SENTRY_TRACES_SAMPLE_RATEis set above 0 along with the DSN.What changed
error-reporting-sentry.mts:setCurrentClient,tracesSampleRatefrom the new env var (default 0), andbeforeSendTransaction, which rebuilds each transaction from an allowlist the same waybeforeSendrebuilds events. Inputs, outputs, headers, user data, tags and child spans are dropped.server.mts: thetools/callhandler runs insidestartSpan({ name: 'tools/call <tool>', op: 'mcp.server', forceTransaction: true, ... })withmcp.method.name,mcp.tool.name,mcp.transport(the server's real transport),network.transport,mcp.client.name/versionandmcp.tool.result.is_error. The handler body is unchanged apart from its indentation.claude-code,cursor,curl, …, elseother), always without a prefix.Heads-up for reviewers
wrapMcpServerWithSentrycan't be used here, because the server uses the low-levelServerwithsetRequestHandler. The span is manual and follows the Sentry MCP cookbook.startNewTrace,parentSpan: null). Core's default scope stack isn't async-aware, so concurrent calls would otherwise parent each other.mcp.clienttags change for clients named only by their User-Agent: unlisted products are nowother, with no version.ua:. Dropping that prefix is a depscan follow-up, listed below.Testing
pnpm test: 74 files, 692 tests pass. New cases: the span attributes over the real HTTP stack (success, upstream 502, unknown tool), no transactions when the sample rate is unset, a separate trace per call, a canary leak check, andsanitizeTransactionallowlist unit tests.pnpm run checkpasses (fmt, lint, typecheck, build, versions, scan). The e2e testtest/e2e/sentry.test.mtspasses.Follow-ups (out of scope)
ua:prefix so both layers send bare client names.Overlap check
No worktree or branch named
surf-2269-mcp-metricsexists locally (git worktree list,git branch -a), so overlap with that work couldn't be checked.Slides
🤖 Generated with Claude Code