feat(mcp): add Sentry monitoring spans#551
Conversation
Issue: AP-363
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
📝 WalkthroughWalkthroughAdds Sentry tracing to the MCP worker: a shared ChangesMCP Sentry Tracing Instrumentation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
AP-363 review — Sentry MCP monitoring spans
Verdict: No blocking issues. Recommend human review before merge (risk-security-sensitive).
Acceptance criteria
| Criterion | Status |
|---|---|
@sentry/cloudflare ≥ 9.44.0 |
✅ Already ^10.57.0 |
Inactive without SENTRY_DSN |
✅ enabled: false, no tracesSampleRate |
tracesSampleRate: 1.0 when DSN set |
✅ mcpSentryOptions |
| Span metadata only (no args/results) | ✅ Manual attributes are method/tool/session/id; tests assert no arg leakage |
SENTRY_DSN optional in secret routing |
✅ required: false, source: "sentry", deploy won't fail if unset |
Security / privacy
- Manual span attributes look safe: only
mcp.tool.namefromparams.name, notarguments. - Error spans record
mcp.error.code(enum machine codes), noterror.message. - Shared
dataCollectiondisablesuserInfo, allhttpBodies, and genAI I/O — important guardrail withtracesSampleRate: 1.0. - Residual:
mcp.session.idand client-suppliedmcp.request.idare correlation metadata sent to Sentry when DSN is configured.
Scope note
packages/worker-runtime/src/sentry.ts dataCollection applies to every worker using sentryOptions (api, upload, content, jobs, stream, web, apex, mcp). This is fleet-wide privacy hardening, not MCP-only; only MCP gets tracesSampleRate: 1.0.
Non-blocking follow-ups
- Consider gating
traceMcpRequestwhen!options.enabledto avoid noopstartSpanoverhead. - Document/confirm
PREVIEW_SENTRY_DSN/PRODUCTION_SENTRY_DSNin CI before enabling in hosted envs. - Production
tracesSampleRate: 1.0is ticket-required but warrants ops sign-off on volume/cost.
Automation recommendation: comment + human review; do not auto-approve.
Sent by Cursor Automation: First Pass PR Reviewer
There was a problem hiding this comment.
First-pass review (AP-363)
Risk: medium
Decision: needs human review
Ticket triage
- Intended change: Enable optional Sentry MCP monitoring on the hosted MCP Worker via
SENTRY_DSN, with manualmcp.serverspans (method/tool/session metadata) and no payload capture. - Scope match: Yes — matches AP-363 acceptance criteria across
sentry-mcp.ts,transport.ts,mcpSentryOptions, secret routing, and tests.
Review findings
Blocking: None. Privacy constraints look correctly enforced:
- Spans record method, tool name, session id, request id, and error codes only — not
params.arguments, tool results, orerror.message. - Shared
sentryOptionssetsdataCollectionto disable user info, HTTP bodies, and genAI I/O. - Tracing is gated behind a trimmed
SENTRY_DSN;tracesSampleRate: 1.0applies only when enabled. traceMcpRequestruns only after bearer auth succeeds indispatchMcpRequest.SENTRY_DSNis optional in secret routing (not inGENERATABLE; deploy tolerates absence).
Non-blocking:
traceMcpRequestalways callsSentry.startSpaneven when Sentry is disabled (SDK should no-op; could gate onenabledfor clarity).packages/worker-runtime/src/sentry.tsdataCollectionhardening applies fleet-wide to any worker usingsentryOptions, not only MCP — intentional defense-in-depth, but worth noting in rollout docs.- Auth/parse failures (401, invalid JSON) are not traced — acceptable for privacy, minor observability gap.
- Hardcoded
mcp.server.version: "0.1.0"may drift from package version.
Merge checklist
- Ticket linked: ✅ AP-363
- Scope matches: ✅
- Checks green:
⚠️ not verified in this run (focusedsentry-mcp.test.tspassed locally; rely on CIpnpm verify) - Tests/docs appropriate: ✅ focused unit tests for options, spans, and secret routing
- No blocking findings: ✅
- No high-risk areas: ❌ —
risk-security-sensitivelabel; third-party telemetry, optional secret provisioning (PREVIEW_SENTRY_DSN/PRODUCTION_SENTRY_DSN), andtracesSampleRate: 1.0need human sign-off before production enablement - Merge-safe: ✅ code-only; no deploy/secret writes in this PR
Recommendation
Needs human review — implementation looks correct and privacy-conscious, but production Sentry enablement is a deliberate ops/security decision outside first-pass automation scope. A human should confirm CI secret wiring and Sentry project retention/access before merging if SENTRY_DSN will be set in hosted envs.
Sent by Cursor Automation: First Pass PR Reviewer
|
agent-paste PR preview resources were cleaned up. The shared Preview GitHub Environment is retained for future preview deploys. |


Summary
Add MCP-aware Sentry monitoring for the hosted MCP Worker without hardcoding a DSN or collecting MCP payloads.
Changes
SENTRY_DSNis configured.SENTRY_DSNas optional provider-managed config.Risk: HIGH
SENTRY_DSN.Test plan
pnpm --filter @agent-paste/mcp testpnpm --filter @agent-paste/worker-runtime testpnpm vitest run scripts/lib/secret-routing.test.mjspnpm --filter @agent-paste/mcp buildpnpm --filter @agent-paste/worker-runtime buildpnpm exec biome check apps/mcp/src/index.ts apps/mcp/src/index.test.ts apps/mcp/src/transport.ts apps/mcp/src/sentry-mcp.ts apps/mcp/src/sentry-mcp.test.ts packages/worker-runtime/src/sentry.ts packages/worker-runtime/src/sentry.test.ts scripts/lib/secret-routing.mjs scripts/lib/secret-routing.test.mjsgit diff --checkpnpm verifygitleaks,biome,typecheckpnpm test:coverage:strict,pnpm verifyReview
Issue: AP-363
Summary by CodeRabbit
Release Notes
New Features
Improvements