fix(core): runtime control of telemetry (#10663)

This commit is contained in:
forehalo
2025-03-06 09:56:13 +00:00
parent 93920f9895
commit 56b842f2e1
5 changed files with 70 additions and 51 deletions

View File

@@ -8,39 +8,42 @@ import {
} from 'react-router-dom';
function createSentry() {
let enabled = true;
let client: Sentry.BrowserClient | undefined;
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,
});
if (!globalThis.SENTRY_RELEASE) {
// https://docs.sentry.io/platforms/javascript/guides/react/#configure
client = Sentry.init({
dsn: process.env.SENTRY_DSN,
debug: BUILD_CONFIG.debug ?? false,
environment: process.env.BUILD_TYPE ?? 'development',
integrations: [
Sentry.reactRouterV6BrowserTracingIntegration({
useEffect,
useLocation,
useNavigationType,
createRoutesFromChildren,
matchRoutes,
}),
],
}) as Sentry.BrowserClient;
Sentry.setTags({
distribution: BUILD_CONFIG.distribution,
appVersion: BUILD_CONFIG.appVersion,
editorVersion: BUILD_CONFIG.editorVersion,
});
}
},
enable() {
enabled = true;
if (client) {
client.getOptions().enabled = true;
}
},
disable() {
enabled = false;
if (client) {
client.getOptions().enabled = false;
}
},
};