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,6 +295,7 @@ function App(): JSX.Element {
Userpilot.initialize(process.env.USERPILOT_KEY); Userpilot.initialize(process.env.USERPILOT_KEY);
} }
if (!isSentryInitialized) {
Sentry.init({ Sentry.init({
dsn: process.env.SENTRY_DSN, dsn: process.env.SENTRY_DSN,
tunnel: process.env.TUNNEL_URL, tunnel: process.env.TUNNEL_URL,
@ -312,6 +315,9 @@ function App(): JSX.Element {
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. 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. 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