diff --git a/frontend/src/AppRoutes/index.tsx b/frontend/src/AppRoutes/index.tsx index df9b1c996a..c40a3df17b 100644 --- a/frontend/src/AppRoutes/index.tsx +++ b/frontend/src/AppRoutes/index.tsx @@ -60,6 +60,8 @@ function App(): JSX.Element { const { isCloudUser, isEnterpriseSelfHostedUser } = useGetTenantLicense(); + const [isSentryInitialized, setIsSentryInitialized] = useState(false); + const enableAnalytics = useCallback( (user: IUser): void => { // wait for the required data to be loaded before doing init for anything! @@ -293,25 +295,29 @@ function App(): JSX.Element { Userpilot.initialize(process.env.USERPILOT_KEY); } - Sentry.init({ - dsn: process.env.SENTRY_DSN, - tunnel: process.env.TUNNEL_URL, - environment: 'production', - integrations: [ - Sentry.browserTracingIntegration(), - Sentry.replayIntegration({ - maskAllText: false, - blockAllMedia: false, - }), - ], - // Performance Monitoring - tracesSampleRate: 1.0, // Capture 100% of the transactions - // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled - tracePropagationTargets: [], - // Session Replay - replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production. - replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur. - }); + if (!isSentryInitialized) { + Sentry.init({ + dsn: process.env.SENTRY_DSN, + tunnel: process.env.TUNNEL_URL, + environment: 'production', + integrations: [ + Sentry.browserTracingIntegration(), + Sentry.replayIntegration({ + maskAllText: false, + blockAllMedia: false, + }), + ], + // Performance Monitoring + tracesSampleRate: 1.0, // Capture 100% of the transactions + // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled + tracePropagationTargets: [], + // Session Replay + replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production. + replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur. + }); + + setIsSentryInitialized(true); + } } else { posthog.reset(); Sentry.close(); @@ -320,6 +326,7 @@ function App(): JSX.Element { window.cioanalytics.reset(); } } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [isCloudUser, isEnterpriseSelfHostedUser]); // if the user is in logged in state