-
Notifications
You must be signed in to change notification settings - Fork 5
chore: migrated to sentry/next #499
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: develop
Are you sure you want to change the base?
Conversation
…se `rewriteFramesIntegration`; added `validate: true` in SentryWebpackPlugin
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis update refactors Sentry integration in a Next.js project by adopting the official Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
⏰ 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 (
|
- Replace constructor usage with function-based API for v2 compatibility - Update import from default export to named export
next.config.js
Outdated
include: ".next", | ||
ignore: ["node_modules"], | ||
stripPrefix: ["webpack://_N_E/"], | ||
urlPrefix: `~${basePath}/_next`, | ||
release: COMMIT_SHA, |
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.
I think all these parameters are already deprecated (at least using version 8.x), are they? Why don't you upgrade to version 8.x yet?
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.
Okay, will update it to v8.
- Remove legacy Sentry setup and config - Remove usage of @sentry/browser and @sentry/node - Add updated Sentry configuration for both client and server using @sentry/nextjs
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: 1
🧹 Nitpick comments (1)
next.config.js (1)
102-105
: Plugin composition order: wrap once, avoid nesting
withSentryConfig
already returns a fully-formed Next config.
Wrapping an anonymous function that internally re-applies other plugins is perfectly valid, but harder to debug.A flatter, more idiomatic approach is:
-const plugins = [withBundleAnalyzer]; -const configWithPlugins = plugins.reduce((config, plugin) => plugin(config), nextConfig); -module.exports = withSentryConfig(() => configWithPlugins, sentryWebpackPluginOptions); +const configWithPlugins = withBundleAnalyzer(nextConfig); +module.exports = withSentryConfig(configWithPlugins, sentryWebpackPluginOptions);Same behaviour, simpler call-stack.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (5)
next.config.js
(3 hunks)package.json
(1 hunks)pages/_app.tsx
(1 hunks)sentry.client.config.ts
(1 hunks)sentry.server.config.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- sentry.server.config.ts
- sentry.client.config.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- package.json
🔇 Additional comments (2)
next.config.js (2)
8-9
: Import looks good – but confirm package parity
withSentryConfig
is pulled from@sentry/nextjs
, which assumes you’ve removed the deprecated@sentry/webpack-plugin
path. Good catch.
No action required.
28-35
:❓ Verification inconclusive
release
may resolve toundefined
– pass it conditionallyIf none of the
*_COMMIT_SHA
/SOURCE_VERSION
env-vars are set,COMMIT_SHA
isundefined
.
Passing that literal value overrides Sentry’s built-in release detection and can lead to a release named"undefined"
on Sentry.-const sentryWebpackPluginOptions = { - silent: false, - authToken: SENTRY_AUTH_TOKEN, - org: SENTRY_ORG, - project: SENTRY_PROJECT, - release: COMMIT_SHA, -}; +const sentryWebpackPluginOptions = { + silent: false, + authToken: SENTRY_AUTH_TOKEN, + org: SENTRY_ORG, + project: SENTRY_PROJECT, + ...(COMMIT_SHA ? { release: COMMIT_SHA } : {}), +};While you’re here, consider failing the build early (
throw
) if the auth token / org / project are missing in CI to avoid silent mis-configuration.
To verify how
COMMIT_SHA
(and related env vars) are defined and whether it can beundefined
, let’s locate its declaration and view the surrounding context innext.config.js
. Please run:
🏁 Script executed:
#!/usr/bin/env bash set -euo pipefail # Locate next.config.js config_file=$(fd --hidden --exact-name next.config.js . | head -n1) if [[ -z "$config_file" ]]; then echo "ERROR: next.config.js not found" exit 1 fi echo "=== Found: $config_file ===" echo # Show where COMMIT_SHA is defined or referenced throughout the repo echo "---- grep for COMMIT_SHA definitions/references ----" rg -n "COMMIT_SHA" . echo # Display the first 100 lines of next.config.js for context echo "---- Showing $config_file (lines 1–100) ----" sed -n '1,100p' "$config_file"Length of output: 312
To locate and inspect how
COMMIT_SHA
is set in your Next.js config, please run:#!/usr/bin/env bash set -euo pipefail # 1. Find next.config.js (try fd, then fallback to find) if config_file=$(fd next.config.js -t f | head -n1); then : elif config_file=$(find . -maxdepth 3 -type f -name "next.config.js" | head -n1); then : else echo "ERROR: next.config.js not found" exit 1 fi echo "=== Using config file: $config_file ===" # 2. Show where COMMIT_SHA is declared or referenced echo echo "---- COMMIT_SHA references/declarations ----" rg -n "COMMIT_SHA" "$config_file" || echo "(none in this file)" # 3. Show top 100 lines for context (imports/env extraction) echo echo "---- First 100 lines of $config_file ----" sed -n '1,100p' "$config_file"
Let’s explicitly locate your
next.config.js
and inspect howCOMMIT_SHA
(and other SENTRY_*/env vars) are defined and used:#!/usr/bin/env bash set -euo pipefail # 1. Find next.config.js anywhere in the repo config_file=$(find . -type f -name "next.config.js" | head -n1) if [[ -z "$config_file" ]]; then echo "ERROR: next.config.js not found" exit 1 fi echo ">>> Using: $config_file" echo # 2. Show occurrences of COMMIT_SHA, SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT echo "---- ENV VAR REFERENCES in $config_file ----" rg -nE "COMMIT_SHA|SENTRY_AUTH_TOKEN|SENTRY_ORG|SENTRY_PROJECT" "$config_file" || echo "(no matches)" echo # 3. Dump the top 200 lines for context (imports / env desctructuring) echo "---- First 200 lines of $config_file ----" sed -n '1,200p' "$config_file"
#!/usr/bin/env bash set -euo pipefail # 1. Locate next.config.js config_file=$(find . -type f -name "next.config.js" | head -n1) if [[ -z "$config_file" ]]; then echo "ERROR: next.config.js not found" exit 1 fi echo ">>> Inspecting: $config_file" echo # 2. Check how COMMIT_SHA (and SOURCE_VERSION) are referenced echo "---- ENV VAR REFERENCES ----" grep -En "process\.env\.(COMMIT_SHA|SOURCE_VERSION)" "$config_file" || echo "(no direct references)" echo # 3. Dump first 200 lines for context echo "---- First 200 lines of $config_file ----" head -n 200 "$config_file"
Conditionally include Sentry
release
and enforce required env-varsIn
next.config.js
(lines 28–35), avoid passingrelease: COMMIT_SHA
unconditionally—ifCOMMIT_SHA
is everundefined
, you’ll end up with a release named"undefined"
in Sentry. For example:const sentryWebpackPluginOptions = { silent: false, authToken: SENTRY_AUTH_TOKEN, org: SENTRY_ORG, project: SENTRY_PROJECT, - release: COMMIT_SHA, + ...(COMMIT_SHA ? { release: COMMIT_SHA } : {}), };Additionally, consider throwing a descriptive error early (e.g. in CI) if any of
SENTRY_AUTH_TOKEN
,SENTRY_ORG
,SENTRY_PROJECT
(or your commit‐SHA env-vars) are missing to avoid silent misconfiguration.Before committing, please verify whether
COMMIT_SHA
(or your fallbackSOURCE_VERSION
) could ever be unset in your build environment—if it’s guaranteed to always exist, you can skip the conditional spread.
Replaced legacy Sentry packages (@sentry/browser and @sentry/node) with the unified @sentry/nextjs SDK for improved support and easier configuration in Next.js.
Changes Made:
@sentry/nextjs
@sentry/nextjs
best practicesWhy ?
-The
@sentry/nextjs
package provides a single solution tailored for Next.js apps, enabling better SSR/ISR error tracking and simplifying setup.Chores