|
1 | | -import { init, Replay } from '@sentry/nextjs'; |
| 1 | +import { SENTRY_DSN, SENTRY_ENABLE } from '@/next.constants.mjs'; |
2 | 2 |
|
3 | | -import { SENTRY_DSN, VERCEL_ENV } from '@/next.constants.mjs'; |
4 | | - |
5 | | -init({ |
6 | | - // Only run Sentry on Vercel Environment |
7 | | - enabled: !!VERCEL_ENV, |
8 | | - // Tell Sentry where to send events |
9 | | - dsn: SENTRY_DSN, |
10 | | - // Percentage of events to send to Sentry (1% of them) (for performance metrics) |
11 | | - tracesSampleRate: 0.01, |
12 | | - // Percentage of sessions to sample (1%) |
13 | | - replaysSessionSampleRate: 0.01, |
14 | | - // Percentage of errors to sample (all of them) |
15 | | - replaysOnErrorSampleRate: 1.0, |
16 | | - // Support replaying client sessions to capture unhappy paths |
17 | | - integrations: [new Replay()], |
18 | | - // We only want to capture errors from _next folder on production |
19 | | - // We don't want to capture errors from preview branches here |
20 | | - allowUrls: ['https://nodejs.org/_next'], |
21 | | - // Filter-out Events/Errors that are invalid for us |
22 | | - beforeSend: (event, hint) => { |
23 | | - const originalException = hint.originalException as Error; |
24 | | - |
25 | | - // All the Events we send must have a message and stack trace |
26 | | - if (originalException?.message && originalException?.stack) { |
27 | | - // All our Events come eventually from code that originates on node_modules |
28 | | - // so everything else should be discarded |
29 | | - // Even React Errors or other errors will eventually have node_modules in the code |
30 | | - if (String(originalException.stack).includes('node_modules')) { |
31 | | - return event; |
32 | | - } |
33 | | - } |
34 | | - |
35 | | - return null; |
36 | | - }, |
37 | | -}); |
| 3 | +// This lazy-loads Sentry on the Browser |
| 4 | +import('@sentry/nextjs').then(({ init }) => |
| 5 | + init({ |
| 6 | + // Only run Sentry on Vercel Environment |
| 7 | + enabled: SENTRY_ENABLE, |
| 8 | + // Tell Sentry where to send events |
| 9 | + dsn: SENTRY_DSN, |
| 10 | + // Disable Sentry Tracing as we don't need to have it |
| 11 | + // as Vercel already does Web Vitals and Performance Measurement on Client-Side |
| 12 | + enableTracing: false, |
| 13 | + // We only want to capture errors from _next folder on production |
| 14 | + // We don't want to capture errors from preview branches here |
| 15 | + allowUrls: ['https://nodejs.org/_next'], |
| 16 | + }) |
| 17 | +); |
0 commit comments