Initialize Sentry as early as possible in your application, before any other code runs:
import * as Sentry from '@sentry/browser';Sentry.init({ dsn: 'YOUR_DSN_HERE', // Performance Monitoring integrations: [ Sentry.browserTracingIntegration(), Sentry.replayIntegration(), ], // Set tracesSampleRate to 1.0 to capture 100% // of transactions for performance monitoring. tracesSampleRate: 1.0, // Capture Replay for 10% of all sessions, // plus for 100% of sessions with an error replaysSessionSampleRate: 0.1, replaysOnErrorSampleRate: 1.0,});
// Automatic - uncaught errors are captured automaticallythrow new Error('This will be captured');// Manual capturetry { riskyOperation();} catch (error) { Sentry.captureException(error);}// Capture a messageSentry.captureMessage('Something went wrong', 'warning');
Replay user sessions to understand what happened before an error:
import * as Sentry from '@sentry/browser';Sentry.init({ dsn: 'YOUR_DSN_HERE', integrations: [ Sentry.replayIntegration({ // Mask all text content maskAllText: true, // Block all media elements blockAllMedia: true, }), ], replaysSessionSampleRate: 0.1, replaysOnErrorSampleRate: 1.0,});
Collect user feedback when errors occur:
import * as Sentry from '@sentry/browser';Sentry.init({ dsn: 'YOUR_DSN_HERE', integrations: [ Sentry.feedbackIntegration({ // Automatically show feedback form on error autoInject: true, colorScheme: 'light', }), ],});
Profile JavaScript performance:
import * as Sentry from '@sentry/browser';Sentry.init({ dsn: 'YOUR_DSN_HERE', integrations: [ Sentry.browserProfilingIntegration(), ], profilesSampleRate: 1.0,});
import * as Sentry from '@sentry/browser';Sentry.init({ dsn: 'YOUR_DSN_HERE', transport: Sentry.makeBrowserOfflineTransport(Sentry.makeFetchTransport),});