The Node.js® Website
at main 2.4 kB view raw
1import { 2 Dedupe, 3 Breadcrumbs, 4 HttpContext, 5 LinkedErrors, 6 BrowserClient, 7 getCurrentHub, 8 defaultStackParser, 9 makeFetchTransport, 10} from '@sentry/nextjs'; 11 12import { 13 SENTRY_DSN, 14 SENTRY_ENABLE, 15 SENTRY_CAPTURE_RATE, 16 SENTRY_TUNNEL, 17} from '@/sentry.constants.mjs'; 18 19// This creates a custom Sentry Client with minimal integrations 20export const sentryClient = new BrowserClient({ 21 // Only run Sentry on Vercel Environment 22 enabled: SENTRY_ENABLE, 23 // Provide Sentry's Secret Key 24 dsn: SENTRY_DSN, 25 // Sentry's Error Transport Mechanism 26 transport: makeFetchTransport, 27 // Sentry's Stack Trace Parser 28 stackParser: defaultStackParser, 29 // All supported Integrations by us 30 integrations: [ 31 new Dedupe(), 32 new HttpContext(), 33 new Breadcrumbs(), 34 new LinkedErrors(), 35 ], 36 // We only want to allow ingestion from these pre-selected allowed URLs 37 // Note that the vercel.app prefix is for our Pull Request Branch Previews 38 allowUrls: ['https://nodejs.org/', /^https:\/\/.+\.vercel\.app/], 39 // Percentage of events to send to Sentry (1% of them) (for performance metrics) 40 tracesSampleRate: SENTRY_CAPTURE_RATE, 41 // Percentage of events to send to Sentry (1% of them) (for session replays) 42 replaysSessionSampleRate: SENTRY_CAPTURE_RATE, 43 // Percentage of events to send to Sentry (1% of them) (for session replays when error happens) 44 replaysOnErrorSampleRate: 1.0, 45 // Provides a custom Sentry Tunnel Router 46 // @note these are components of the Sentry DSN string 47 // @see @sentry/nextjs/esm/client/tunnelRoute.js 48 tunnel: SENTRY_TUNNEL(`?o=4506191161786368&p=4506191307735040`), 49 // Adds custom filtering before sending an Event to Sentry 50 beforeSend: (event, hint) => { 51 // Attempts to grab the original Exception before any "magic" happens 52 const exception = hint.originalException as Error; 53 54 // We only want to capture Errors that have a Stack Trace and that are not Anonymous Errors 55 return exception?.stack && !exception.stack.includes('<anonymous>') 56 ? event 57 : null; 58 }, 59}); 60 61// Attaches this Browser Client to Sentry 62getCurrentHub().bindClient(sentryClient); 63 64// Loads this Dynamically to avoid adding this to the main bundle (initial load) 65import('@sentry/nextjs').then(({ Replay, BrowserTracing }) => { 66 sentryClient.addIntegration(new Replay({ maskAllText: false })); 67 sentryClient.addIntegration(new BrowserTracing()); 68});