Skip to content

Conversation

sunilsabatp
Copy link
Contributor

@sunilsabatp sunilsabatp commented Jun 10, 2025

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:

    • Installed @sentry/nextjs
    • Updated initialization logic in both client and server environments
    • Refactored Sentry config to align with @sentry/nextjs best practices
  • Why ?
    -The @sentry/nextjs package provides a single solution tailored for Next.js apps, enabling better SSR/ISR error tracking and simplifying setup.

  • Chores

    • Updated Sentry dependencies to the latest versions and consolidated packages.
    • Simplified Sentry integration by adopting the official Next.js Sentry plugin and removing manual setup.
    • Added dedicated client and server Sentry configuration files with environment-based error tracking and ignored error filters.

…se `rewriteFramesIntegration`; added `validate: true` in SentryWebpackPlugin
Copy link

vercel bot commented Jun 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
donate-with-planet ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 13, 2025 11:40am

Copy link

coderabbitai bot commented Jun 10, 2025

Walkthrough

This update refactors Sentry integration in a Next.js project by adopting the official withSentryConfig wrapper for configuration and source map uploading. It consolidates Sentry dependencies into @sentry/nextjs, removes manual Webpack plugin setup and client initialization, and introduces separate client and server Sentry config files with environment-based enabling and error filtering.

Changes

File(s) Change Summary
package.json Removed @sentry/browser, @sentry/integrations, @sentry/node; added @sentry/nextjs v8.55.0; upgraded @sentry/webpack-plugin to v2.22.7.
next.config.js Replaced manual Sentry Webpack plugin setup with withSentryConfig HOC; simplified Sentry plugin options; removed custom webpack function.
pages/_app.tsx Removed all Sentry initialization and imports except changed import to @sentry/nextjs; no config code remains.
sentry.client.config.ts Added new client-side Sentry config with init from @sentry/nextjs, DSN from env, production-only enablement, and error ignore list.
sentry.server.config.ts Added new server-side Sentry config with init from @sentry/nextjs, DSN from env, and production-only enablement.

Poem

🐇
In code's green fields, we leap and bound,
Sentry’s new path is safe and sound.
Plugins wrapped with official grace,
Errors filtered, found their place.
Dependencies trimmed, configs neat,
A rabbit’s hop makes tracking sweet!
🌿✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b724d97 and afae838.

📒 Files selected for processing (1)
  • pages/_app.tsx (0 hunks)
💤 Files with no reviewable changes (1)
  • pages/_app.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: ESLint on Ubuntu
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

- Replace constructor usage with function-based API for v2 compatibility
- Update import from default export to named export
@sunilsabatp sunilsabatp requested a review from mohitb35 June 10, 2025 08:07
@sunilsabatp sunilsabatp changed the title chore: upgrade Sentry to v7.120.3 and update initialization code to u… chore: upgrade Sentry to v7.120.3 Jun 10, 2025
next.config.js Outdated
Comment on lines 96 to 100
include: ".next",
ignore: ["node_modules"],
stripPrefix: ["webpack://_N_E/"],
urlPrefix: `~${basePath}/_next`,
release: COMMIT_SHA,
Copy link
Collaborator

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?

Copy link
Contributor Author

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
Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between abf5505 and b724d97.

⛔ 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 to undefined – pass it conditionally

If none of the *_COMMIT_SHA / SOURCE_VERSION env-vars are set, COMMIT_SHA is undefined.
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 be undefined, let’s locate its declaration and view the surrounding context in next.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 how COMMIT_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-vars

In next.config.js (lines 28–35), avoid passing release: COMMIT_SHA unconditionally—if COMMIT_SHA is ever undefined, 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 fallback SOURCE_VERSION) could ever be unset in your build environment—if it’s guaranteed to always exist, you can skip the conditional spread.

@sunilsabatp sunilsabatp changed the title chore: upgrade Sentry to v7.120.3 chore: migrated to sentry/next Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants