feat: initialize sentry only once (#7768)

This commit is contained in:
Yunus M 2025-04-29 21:31:28 +05:30 committed by GitHub
parent 629c54d3f9
commit e47c7cc17b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -60,6 +60,8 @@ function App(): JSX.Element {
const { isCloudUser, isEnterpriseSelfHostedUser } = useGetTenantLicense(); const { isCloudUser, isEnterpriseSelfHostedUser } = useGetTenantLicense();
const [isSentryInitialized, setIsSentryInitialized] = useState(false);
const enableAnalytics = useCallback( const enableAnalytics = useCallback(
(user: IUser): void => { (user: IUser): void => {
// wait for the required data to be loaded before doing init for anything! // 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); Userpilot.initialize(process.env.USERPILOT_KEY);
} }
Sentry.init({ if (!isSentryInitialized) {
dsn: process.env.SENTRY_DSN, Sentry.init({
tunnel: process.env.TUNNEL_URL, dsn: process.env.SENTRY_DSN,
environment: 'production', tunnel: process.env.TUNNEL_URL,
integrations: [ environment: 'production',
Sentry.browserTracingIntegration(), integrations: [
Sentry.replayIntegration({ Sentry.browserTracingIntegration(),
maskAllText: false, Sentry.replayIntegration({
blockAllMedia: false, maskAllText: false,
}), blockAllMedia: false,
], }),
// Performance Monitoring ],
tracesSampleRate: 1.0, // Capture 100% of the transactions // Performance Monitoring
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled tracesSampleRate: 1.0, // Capture 100% of the transactions
tracePropagationTargets: [], // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
// Session Replay tracePropagationTargets: [],
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. // Session Replay
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur. 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 { } else {
posthog.reset(); posthog.reset();
Sentry.close(); Sentry.close();
@ -320,6 +326,7 @@ function App(): JSX.Element {
window.cioanalytics.reset(); window.cioanalytics.reset();
} }
} }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isCloudUser, isEnterpriseSelfHostedUser]); }, [isCloudUser, isEnterpriseSelfHostedUser]);
// if the user is in logged in state // if the user is in logged in state