8000 Add Sentry integration by devkiran · Pull Request #2512 · dubinc/dub · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Add Sentry integration #2512

wants to merge 16 commits into from

Conversation

devkiran
Copy link
Collaborator
@devkiran devkiran commented Jun 11, 2025

Summary by CodeRabbit

  • New Features
    • Integrated Sentry error monitoring across the web application for enhanced error tracking and reporting.
    • Added global error handling to automatically report unhandled errors to Sentry and display a user-friendly error page.
  • Configuration
    • Updated environment example file with Sentry-related variables for easier setup.
    • Enhanced Next.js configuration to support Sentry integration and instrumentation.
    • Added server and edge runtime configurations for Sentry initialization.
  • Dependencies
    • Added Sentry SDK for Next.js to project dependencies.
  • Chores
    • Updated ignore rules to exclude Sentry build plugin files.

Copy link
vercel bot commented Jun 11, 2025

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

Name Status Preview Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview Jun 13, 2025 2:54am

Copy link
Contributor
coderabbitai bot commented Jun 11, 2025

Walkthrough

Sentry 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 .gitignore and dependencies were also updated accordingly.

Changes

File(s) Change Summary
.gitignore Added Sentry-related ignore rule for .env.sentry-build-plugin.
apps/web/.env.example Added Sentry environment variables for DSN and CLI configuration.
apps/web/app/global-error.tsx Added GlobalError React component to capture and report errors to Sentry.
apps/web/instrumentation-client.ts, apps/web/instrumentation.ts Added Sentry client, server, and edge instrumentation setup and exported relevant hooks/functions.
apps/web/lib/api/errors.ts Integrated Sentry error reporting into API error handler.
apps/web/next.config.js Wrapped Next.js config with Sentry, added Sentry options, enabled instrumentation hook in production.
apps/web/package.json Added @sentry/nextjs package dependency.
apps/web/sentry.edge.config.ts, apps/web/sentry.server.config.ts Added Sentry initialization files for edge and server runtimes.

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
Loading

Poem

In the warren of code, where bugs sometimes hide,
Sentry now listens, with eyes open wide.
Errors and mishaps, no longer a fright—
They’re logged and reported, both day and night.
With config and hooks, our app’s in good cheer,
Hopping ahead, with less to fear! 🐇✨


📜 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 c34dee7 and 80417e0.

📒 Files selected for processing (2)
  • apps/web/sentry.edge.config.ts (1 hunks)
  • apps/web/sentry.server.config.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/sentry.server.config.ts
  • apps/web/sentry.edge.config.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
✨ 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.

Copy link
socket-security bot commented Jun 11, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​sentry/​nextjs@​9.28.19610090100100

View full report

Copy link
bug0-qa-agent bot commented Jun 11, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2512:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

Copy link
bug0-qa-agent bot commented Jun 11, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2512:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

Copy link
bug0-qa-agent bot commented Jun 11, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2512:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

Copy link
bug0-qa-agent bot commented Jun 11, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2512:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

@devkiran devkiran marked this pull request as ready for review June 11, 2025 12:30
@devkiran devkiran requested a review from steven-tey June 11, 2025 12:30
Copy link
Contributor
@coderabbitai coderabbitai bot left a comment
8000

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 issue

Comma operator drops half of the redirects – only /:segment/:path* survives

Inside 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

  1. On the server you can use SENTRY_DSN instead of the public variant to avoid accidental env mismatches.
  2. Adding environment, release, and tracesSampleRate (or sampleRate 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 runtime

Same remarks as above: prefer SENTRY_DSN, add environment, 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) when process.env.NEXT_PUBLIC_SENTRY_DSN is undefined, 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 sensitivity

The 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 StrictMode

In dev, React mounts components twice which will double-send captureException.
Wrap the call in Sentry.withScope + a flag, or gate it behind process.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 plus sourcemaps.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

📥 Commits

Reviewing files that changed from the base of the PR and between 39cfbfd and c34dee7.

⛔ 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 exist

The 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 valid

The 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 file

Ignoring .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 fine

Importing Sentry here is necessary for server-side capture.


163-163: Nice: unhandled errors are now sent to Sentry

This capture is well-placed after all “expected” branches.

apps/web/instrumentation-client.ts (1)

10-10: Verify SDK version exposes captureRouterTransitionStart

captureRouterTransitionStart is available only from @sentry/nextjs@7.79.0 (SDK 7.79) upwards. If you are below that version the export will be undefined, leading to consumers crashing on invocation.
Confirm the installed version or add a runtime fallback.

-export const >
+export const >
+  Sentry.captureRouterTransitionStart ?? (() => {/* noop */});

Copy link
bug0-qa-agent bot commented Jun 11, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2512:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

Copy link
bug0-qa-agent bot commented Jun 11, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2512:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

8000 Copy link
bug0-qa-agent bot commented Jun 11, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2512:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

Copy link
bug0-qa-agent bot commented Jun 12, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2512:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

Copy link
bug0-qa-agent bot commented Jun 12, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2512:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

Copy link
bug0-qa-agent bot commented Jun 12, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2512:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

Copy link
bug0-qa-agent bot commented Jun 12, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2512:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

Copy link
bug0-qa-agent bot commented Jun 12, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2512:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

Copy link
bug0-qa-agent bot commented Jun 13, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2512:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0