fix: prevent sentry from loading when telemetry is disabled (#10543)

Co-authored-by: forehalo <forehalo@gmail.com>
This commit is contained in:
hackerESQ
2025-03-05 06:09:38 -06:00
committed by GitHub
parent b247b8e26c
commit fed0e0add3
16 changed files with 122 additions and 200 deletions
+50
View File
@@ -0,0 +1,50 @@
import * as Sentry from '@sentry/react';
import { useEffect } from 'react';
import {
createRoutesFromChildren,
matchRoutes,
useLocation,
useNavigationType,
} from 'react-router-dom';
function createSentry() {
let enabled = true;
const wrapped = {
init() {
// https://docs.sentry.io/platforms/javascript/guides/react/#configure
Sentry.init({
enabled: enabled,
dsn: process.env.SENTRY_DSN,
debug: BUILD_CONFIG.debug ?? false,
environment: process.env.BUILD_TYPE ?? 'development',
integrations: [
Sentry.reactRouterV6BrowserTracingIntegration({
useEffect,
useLocation,
useNavigationType,
createRoutesFromChildren,
matchRoutes,
}),
],
beforeSend(event) {
return enabled ? event : null;
},
});
Sentry.setTags({
distribution: BUILD_CONFIG.distribution,
appVersion: BUILD_CONFIG.appVersion,
editorVersion: BUILD_CONFIG.editorVersion,
});
},
enable() {
enabled = true;
},
disable() {
enabled = false;
},
};
return wrapped;
}
export const sentry = createSentry();