-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add Sentry integration #2512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add Sentry integration #2512
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughSentry error monitoring has been integrated into the Next.js web application. This includes configuration files for both server and edge runtimes, updates to environment variable examples, Next.js configuration changes, and new code to capture and report errors to Sentry from global errors and API routes. The Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant App (Next.js)
participant Sentry
User->>App (Next.js): Triggers error (API call, navigation, etc.)
App (Next.js)->>Sentry: captureException(error)
Sentry-->>App (Next.js): Acknowledgement
App (Next.js)->>User: Display error page or message
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
🤖 Bug0 QA Agent Here are the results of the automated tests for PR #2512:
To re-run the tests, please comment |
🤖 Bug0 QA Agent Here are the results of the automated tests for PR #2512:
To re-run the tests, please comment |
🤖 Bug0 QA Agent Here are the results of the automated tests for PR #2512:
To re-run the tests, please comment |
🤖 Bug0 QA Agent Here are the results of the automated tests for PR #2512:
To re-run the tests, please comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
apps/web/next.config.js (1)
142-169
:⚠️ Potential issueComma operator drops half of the redirects – only
/:segment/:path*
survivesInside the
map
callback you return two object literals separated by a comma wrapped in parentheses.
Because of the JavaScript comma operator, the first object is discarded and every top-level/segment
redirect is lost.- ...REDIRECT_SEGMENTS.map( - (segment) => ( - { - source: `/${segment}`, - /* … */ - }, - { - source: `/${segment}/:path*`, - /* … */ - } - ), - ), + ...REDIRECT_SEGMENTS.flatMap((segment) => [ + { + source: `/${segment}`, + /* … */ + }, + { + source: `/${segment}/:path*`, + /* … */ + }, + ]),
🧹 Nitpick comments (8)
apps/web/lib/api/errors.ts (1)
126-127
: Log the full error, not just the message
console.error(error.message)
drops stack traces and contextual properties that are invaluable during debugging.- console.error(error.message); + console.error(error);Keeping the complete object does not leak sensitive data (it is already server-side) and greatly improves triage.
apps/web/sentry.server.config.ts (1)
5-8
: Consider additional Sentry init options & use non-public DSN
- On the server you can use
SENTRY_DSN
instead of the public variant to avoid accidental env mismatches.- Adding
environment
,release
, andtracesSampleRate
(orsampleRate
for errors) gives richer context and enables performance monitoring.Sentry.init({ - dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, - debug: false, + dsn: process.env.SENTRY_DSN ?? process.env.NEXT_PUBLIC_SENTRY_DSN, + debug: false, + environment: process.env.VERCEL_ENV ?? process.env.NODE_ENV, + release: process.env.VERCEL_GIT_COMMIT_SHA, + tracesSampleRate: 0.05, // tune to your needs });apps/web/sentry.edge.config.ts (1)
6-8
: Mirror the server-side improvements for edge runtimeSame remarks as above: prefer
SENTRY_DSN
, addenvironment
,release
, and a sampling rate for consistent telemetry across all runtimes.apps/web/instrumentation-client.ts (1)
5-8
: Guard against missing DSN at runtime
Sentry.init
will still run (and emit a warning) whenprocess.env.NEXT_PUBLIC_SENTRY_DSN
isundefined
, but the SDK won’t actually report errors.
A small guard prevents silent mis-configurations in preview/staging environments:-Sentry.init({ - dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, - debug: false, -}); +const dsn = process.env.NEXT_PUBLIC_SENTRY_DSN; +if (dsn) { + Sentry.init({ + dsn, + debug: false, + }); +}apps/web/.env.example (1)
151-161
: Nice addition – consider clarifying token sensitivityThe new Sentry CLI variables are secrets (especially
SENTRY_AUTH_TOKEN
). A quick inline comment such as “# DO NOT commit real values” helps newcomers avoid accidental leaks.apps/web/instrumentation.ts (1)
3-11
: Edge/Node selection could double-import on unknown runtimes
process.env.NEXT_RUNTIME
should be'nodejs'
or'edge'
, but if the value is unexpectedly missing (custom test runners, storybook, etc.) neither branch runs, leaving Sentry un-initialised.-export async function register() { - if (process.env.NEXT_RUNTIME === 'nodejs') { - await import('./sentry.server.config'); - } - - if (process.env.NEXT_RUNTIME === 'edge') { - await import('./sentry.edge.config'); - } +export async function register() { + switch (process.env.NEXT_RUNTIME) { + case 'nodejs': + await import('./sentry.server.config'); + break; + case 'edge': + await import('./sentry.edge.config'); + break; + default: + // fallback to node config in unknown environments + await import('./sentry.server.config'); + } }apps/web/app/global-error.tsx (1)
7-10
: Prevent duplicate reports in React-18 StrictModeIn dev, React mounts components twice which will double-send
captureException
.
Wrap the call inSentry.withScope
+ a flag, or gate it behindprocess.env.NODE_ENV === 'production'
to avoid noisy duplication while developing.apps/web/next.config.js (1)
252-255
: Disabling source-map upload blocks stack-trace symbolication
widenClientFileUpload: false
plussourcemaps.disable: true
prevents any source maps from reaching Sentry, so stack traces will be unreadable.
If size is a concern consider uploading maps only in CI (hidden-source-map
) rather than turning them off entirely.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (10)
.gitignore
(1 hunks)apps/web/.env.example
(1 hunks)apps/web/app/global-error.tsx
(1 hunks)apps/web/instrumentation-client.ts
(1 hunks)apps/web/instrumentation.ts
(1 hunks)apps/web/lib/api/errors.ts
(3 hunks)apps/web/next.config.js
(4 hunks)apps/web/package.json
(1 hunks)apps/web/sentry.edge.config.ts
(1 hunks)apps/web/sentry.server.config.ts
(1 hunks)
🔇 Additional comments (5)
apps/web/package.json (1)
39-39
:❌ Incorrect review comment
Invalid package version –
@sentry/nextjs
9.x does not existThe latest published major version of
@sentry/nextjs
is currently 8.x; attempting to install^9.28.1
will fail and break every CI / local install.- "@sentry/nextjs": "^9.28.1", + "@sentry/nextjs": "^8.28.1",Please update to a valid version or verify that 9.x has actually been published.
Run to double-check what’s on the registry:
🏁 Script executed:
#!/usr/bin/env bash npm view @sentry/nextjs versions --json | jq '.[-5:]'Length of output: 118
No action needed:
@sentry/nextjs@^9.28.1
is validThe npm registry shows that versions 9.x—including 9.28.1—are published:
npm view @sentry/nextjs versions --json | jq '.[-5:]' # [ # "9.25.1", # "9.26.0", # "9.27.0", # "9.28.0", # "9.28.1" # ]You can safely keep the existing line in apps/web/package.json:
"@sentry/nextjs": "^9.28.1",
Likely an incorrect or invalid review comment.
.gitignore (1)
47-50
: LGTM – good call ignoring Vitest cache & Sentry plugin fileIgnoring
.vitest/
and the Sentry build-plugin env file keeps noise out of the repo and avoids leaking CI artefacts.apps/web/lib/api/errors.ts (2)
3-3
: Import looks fineImporting Sentry here is necessary for server-side capture.
163-163
: Nice: unhandled errors are now sent to SentryThis capture is well-placed after all “expected” branches.
apps/web/instrumentation-client.ts (1)
10-10
: Verify SDK version exposescaptureRouterTransitionStart
captureRouterTransitionStart
is available only from@sentry/nextjs@7.79.0
(SDK 7.79) upwards. If you are below that version the export will beundefined
, leading to consumers crashing on invocation.
Confirm the installed version or add a runtime fallback.-export const > +export const > + Sentry.captureRouterTransitionStart ?? (() => {/* noop */});
🤖 Bug0 QA Agent Here are the results of the automated tests for PR #2512:
To re-run the tests, please comment |
🤖 Bug0 QA Agent Here are the results of the automated tests for PR #2512:
To re-run the tests, please comment |
🤖 Bug0 QA Agent Here are the results of the automated tests for PR #2512:
To re-run the tests, please comment |
🤖 Bug0 QA Agent Here are the results of the automated tests for PR #2512:
To re-run the tests, please comment |
🤖 Bug0 QA Agent Here are the results of the automated tests for PR #2512:
To re-run the tests, please comment |
🤖 Bug0 QA Agent Here are the results of the automated tests for PR #2512:
To re-run the tests, please comment |
🤖 Bug0 QA Agent Here are the results of the automated tests for PR #2512:
To re-run the tests, please comment |
🤖 Bug0 QA Agent Here are the results of the automated tests for PR #2512:
To re-run the tests, please comment |
🤖 Bug0 QA Agent Here are the results of the automated tests for PR #2512:
To re-run the tests, please comment |
Summary by CodeRabbit