|
3 | 3 | // https://docs.sentry.io/platforms/javascript/guides/nextjs/ |
4 | 4 | import * as Sentry from "@sentry/nextjs"; |
5 | 5 |
|
6 | | -Sentry.init({ |
7 | | - dsn: process.env.NEXT_PUBLIC_SENTRY_DSN_CLIENT, |
| 6 | +if (process.env.NODE_ENV === "production") { |
| 7 | + Sentry.init({ |
| 8 | + dsn: process.env.NEXT_PUBLIC_SENTRY_DSN_CLIENT, |
8 | 9 |
|
9 | | - sampleRate: parseFloat(process.env.SENTRY_SAMPLE_RATE ?? "1.0") || 1.0, |
10 | | - // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control. |
11 | | - tracesSampleRate: parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE ?? "0.0") || 0.0, |
| 10 | + sampleRate: parseFloat(process.env.SENTRY_SAMPLE_RATE ?? "1.0") || 1.0, |
| 11 | + // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control. |
| 12 | + tracesSampleRate: parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE ?? "0.0") || 0.0, |
12 | 13 |
|
13 | | - // Define how likely Replay events are sampled. |
14 | | - // This sets the sample rate to be 10%. You may want this to be 100% while |
15 | | - // in development and sample at a lower rate in production |
16 | | - // replaysSessionSampleRate: parseFloat(process.env.SENTRY_REPLAYS_SESSION_SAMPLE_RATE ?? "0.0") || 0.0, |
| 14 | + // Define how likely Replay events are sampled. |
| 15 | + // This sets the sample rate to be 10%. You may want this to be 100% while |
| 16 | + // in development and sample at a lower rate in production |
| 17 | + // replaysSessionSampleRate: parseFloat(process.env.SENTRY_REPLAYS_SESSION_SAMPLE_RATE ?? "0.0") || 0.0, |
17 | 18 |
|
18 | | - // Define how likely Replay events are sampled when an error occurs. |
19 | | - // replaysOnErrorSampleRate: parseFloat(process.env.SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE ?? "0.0") || 0.0, |
| 19 | + // Define how likely Replay events are sampled when an error occurs. |
| 20 | + // replaysOnErrorSampleRate: parseFloat(process.env.SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE ?? "0.0") || 0.0, |
20 | 21 |
|
21 | | - // Setting this option to true will print useful information to the console while you're setting up Sentry. |
22 | | - debug: !!process.env.SENTRY_DEBUG, |
23 | | - beforeSend(event) { |
24 | | - if ( |
25 | | - event.exception?.values?.some( |
26 | | - (e) => |
27 | | - // Ignore fake error "UnhandledRejection: Non-Error promise rejection captured with value: Object Not Found Matching Id:3, MethodName:update, ParamCount:4" |
28 | | - // Raised GH issue: https://github.com/getsentry/sentry-javascript/issues/3440 |
29 | | - e.value?.includes("Non-Error promise rejection captured with") || |
30 | | - e.value?.includes("Object Not Found Matching Id") |
31 | | - ) |
32 | | - ) { |
33 | | - return null; |
34 | | - } |
| 22 | + // Setting this option to true will print useful information to the console while you're setting up Sentry. |
| 23 | + debug: !!process.env.SENTRY_DEBUG, |
| 24 | + beforeSend(event) { |
| 25 | + if ( |
| 26 | + event.exception?.values?.some( |
| 27 | + (e) => |
| 28 | + // Ignore fake error "UnhandledRejection: Non-Error promise rejection captured with value: Object Not Found Matching Id:3, MethodName:update, ParamCount:4" |
| 29 | + // Raised GH issue: https://github.com/getsentry/sentry-javascript/issues/3440 |
| 30 | + e.value?.includes("Non-Error promise rejection captured with") || |
| 31 | + e.value?.includes("Object Not Found Matching Id") |
| 32 | + ) |
| 33 | + ) { |
| 34 | + return null; |
| 35 | + } |
35 | 36 |
|
36 | | - event.tags = { |
37 | | - ...event.tags, |
38 | | - errorSource: "client", |
39 | | - }; |
40 | | - return event; |
41 | | - }, |
42 | | -}); |
| 37 | + event.tags = { |
| 38 | + ...event.tags, |
| 39 | + errorSource: "client", |
| 40 | + }; |
| 41 | + return event; |
| 42 | + }, |
| 43 | + }); |
| 44 | +} |
43 | 45 |
|
44 | | -export const onRouterTransitionStart = Sentry.captureRouterTransitionStart; |
| 46 | +export function onRouterTransitionStart(url: string, navigationType: "push" | "replace" | "traverse") { |
| 47 | + if (process.env.NODE_ENV === "production") { |
| 48 | + Sentry.captureRouterTransitionStart(url, navigationType); |
| 49 | + } |
| 50 | +} |
0 commit comments