Add Sentry Next.js SDK (error monitoring + tracing), inert until DSN set - #1522
Add Sentry Next.js SDK (error monitoring + tracing), inert until DSN set#1522BigSimmo wants to merge 9 commits into
Conversation
Installs @sentry/nextjs and wires init across all three runtimes, merging into the existing production boot guard (src/instrumentation.ts) and Zod JIT-disable hook (src/instrumentation-client.ts) rather than replacing them. Wraps next.config.ts with withSentryConfig using a tunnelRoute so events proxy through this app's own origin instead of *.sentry.io, matching the strict connect-src 'self' CSP. No DSN is configured, so the SDK stays inert (init runs, nothing is sent) until SENTRY_DSN/NEXT_PUBLIC_SENTRY_DSN are set. Scope follows the Sentry "first error" baseline (errors + tracing only) — Session Replay, Logs, and Profiling are deliberately deferred, and dataCollection/includeLocalVariables are left at their conservative defaults given clinical query text can appear in error messages and local variables. Provisioning an actual Sentry project is a new third-party data processor for this clinical app; see docs/outstanding-issues.md #53 for the pending DPA/subprocessor review that should land before this carries real production traffic.
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in:10 minutes Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThe PR integrates ChangesSentry observability
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Browser
participant Next.js
participant SentrySDK
Browser->>Next.js: Load application instrumentation
Next.js->>SentrySDK: Initialize client, Node.js, or Edge runtime
Browser->>SentrySDK: Capture router transition
Next.js->>SentrySDK: Capture global or request error
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
CI triageCI failed on this PR. Automated classification of the 10 failed job(s):
Compared with main CI run #7441 (cancelled). Classification is evidence routing, not permission to ignore a failure. Exact quarantined Playwright identities remain governed by the flake ledger. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/instrumentation-client.ts`:
- Around line 23-26: Implement shared runtime-neutral Sentry scrubber hooks for
beforeSend, beforeSendTransaction, and beforeBreadcrumb, then configure them on
all three Sentry.init calls, including the global-error capture path. Remove
sensitive exception, transaction, and breadcrumb values; return null whenever
sanitization cannot safely establish an acceptable event, and add tests covering
redaction and fail-closed behavior.
🪄 Autofix (Beta)
❌ Autofix failed (check again to retry)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 19f10698-1ebd-4809-b4bf-35bb71f64164
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (8)
.env.examplenext.config.tspackage.jsonsrc/app/global-error.tsxsrc/instrumentation-client.tssrc/instrumentation.tssrc/sentry.edge.config.tssrc/sentry.server.config.ts
Uh oh!
There was an error while loading. Please reload this page.
BigSimmo
commented
Jul 31, 2026
@cursoragent This PR was just reopened. Do not merge, force-push, rebase, or arm auto-merge
|
Tip: What I did
Current CIFresh required checks are in progress on Threads
Residual risks
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. The branch was updated while autofix was in progress. Please try again. |
npm ci failed in CI across every job with "Missing: @emnapi/runtime@1.11.2 from lock file". The npm install that added @sentry/nextjs pulled in rollup (used by the SDK's bundler-plugin toolchain) transitively, but the resulting package-lock.json omitted the @emnapi/runtime@1.11.2 entries nested under @oxc-parser/binding-wasm32-wasi and @oxc-resolver/binding-wasm32-wasi that npm ci's strict validation requires even though they're optional platform-specific packages. A clean rm -rf node_modules && npm install regenerated a complete lockfile; verified locally with npm ci --include=dev (exit 0) and a full npm run verify:cheap pass (445 files / 4659 tests).
npm ci was failing on CI because package-lock.json omitted required @emnapi packages after adding @sentry/nextjs. Regenerate the lockfile and wire shared beforeSend/beforeSendTransaction/beforeBreadcrumb hooks that redact clinical query text, secrets, and request PII (fail closed on scrub errors) across client, Node, and Edge Sentry inits.
Drop the direct @sentry/core type import (knip unlisted dependency) in favor of local event shapes cast to @sentry/nextjs init options, and refresh the enforced client bundle-budget baseline for the intentional @sentry/nextjs client cost (~+22% gzip).
This pull request has been ignored for the connected project Preview Branches by Supabase. |


Summary
@sentry/nextjs@10.69.0and wireSentry.init()across all three Next.js runtimes (client, Node server, Edge), merging into the existingsrc/instrumentation.tsproduction boot guard andsrc/instrumentation-client.tsZod JIT-disable hook rather than replacing either.next.config.tswithwithSentryConfig, usingtunnelRoute: "/monitoring"so browser events proxy through this app's own origin instead of calling*.sentry.iodirectly — verified in the build'sroutes-manifest.jsonas a server-side rewrite to*.ingest.sentry.io, so the existing strictconnect-src 'self' https://*.supabase.coCSP (src/lib/security-headers.ts) needed no change.Sentry.captureException(error)to the existingglobal-error.tsxboundary alongside its currentconsole.error/redacted-diagnostics behavior..env.example(NEXT_PUBLIC_SENTRY_DSN,SENTRY_DSN,SENTRY_AUTH_TOKEN,SENTRY_ORG,SENTRY_PROJECT), all commented out / unset.No DSN is configured anywhere, so the SDK stays inert (init runs, nothing is sent) until a real Sentry project's DSN is added. No Sentry MCP server was available in this environment and the official
@sentry/wizardneeds an interactive browser login, so this was a manual install followingreferences/sdks/nextjs/index.mdfrom thesentry-instrumentskill, scoped to its "first error" baseline (errors + tracing only).Deliberately deferred (not part of this PR): Session Replay, Sentry Logs, and Profiling.
dataCollectionandincludeLocalVariablesare left at their conservative defaults (sendDefaultPii: false, no local-variable capture) because this is a clinical psychiatry KB where error messages and local variables in the RAG/ingestion code paths can contain clinical query text. Provisioning an actual Sentry project is a new third-party data processor for this app — seedocs/outstanding-issues.md#53 (pending DPA/subprocessor review) before this carries real production traffic or before enabling Replay/Logs.Verification
npm run verify:pr-local— exit 0. Decisive lines:Client bundle secret surface check passed./Offline RAG fixture and manifest validation passed (36 golden cases, 23 suites).npm run verify:ui— not run; no UI/routing/styling behavior changed (only aSentry.captureExceptioncall added to an existing error boundary's effect).npm run verify:release— not run; not a release/handoff request.npm run eval:retrieval:quality/npm run eval:rag— not applicable; no retrieval/ranking/answer-generation code touched.npm run check:production-readiness— not run; no clinical workflow, Supabase, or source-governance behavior changed. Flagging for reviewer judgment since this does touch the production boot path (src/instrumentation.ts) and the production build wrapper (next.config.ts).Additionally ran directly against this diff (all green):
npx tsc --noEmit,npm run lint,npm run test(445 files / 4659 tests passed, 4 skipped),tests/instrumentation.test.tsspecifically (11/11 passed — this is the file that exercisesregister()directly and was the highest regression risk from adding a Sentry init call inside it), and a full production build (npm run build, webpack) confirming the/monitoringtunnel rewrite is generated and the client-bundle secret scan still passes.Risk and rollout
@sentry/nextjs) and a wrappednext.config.ts/instrumentation.ts, but the SDK is inert with no DSN configured —Sentry.init({ dsn: undefined, ... })creates no functioning client, so no behavior or data-flow change ships with this PR. The only currently-observable code change is the addedSentry.captureExceptioncall inglobal-error.tsx, which is a no-op without a DSN.SENTRY_DSN/NEXT_PUBLIC_SENTRY_DSN(already the default) to keep the SDK inert without reverting.docs/outstanding-issues.mdHarden authentication and protect sensitive tokens #53 before it carries real clinical/production traffic.Notes
scripts/pr-policy.mjs's classifier does not flag it as clinical-risk (only operational-risk, from thepackage.json/package-lock.json/next.config.tschanges), so no## Clinical Governance Preflightsection is included.SENTRY_AUTH_TOKEN/org/project), get it into production, and complete the DPA/subprocessor review before real traffic flows.Generated by Claude Code
Summary by CodeRabbit
New Features
Documentation
Bug Fixes