From 5d01b93a8dd4433d5a3574f00b733e72898e7248 Mon Sep 17 00:00:00 2001 From: Vladimir Cucu <108150922+vladimir-cucu@users.noreply.github.com> Date: Tue, 5 Dec 2023 08:36:47 +0200 Subject: [PATCH] feat: Enable Sentry only if analyticsEnabled is true (#1673) --- src/components/ErrorBoundary/ErrorBoundary.tsx | 15 ++++++++++----- src/index.tsx | 7 +++++-- src/store/middleware/model-poller.ts | 5 ++++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/components/ErrorBoundary/ErrorBoundary.tsx b/src/components/ErrorBoundary/ErrorBoundary.tsx index 97c0d254b..8d4faa7b0 100644 --- a/src/components/ErrorBoundary/ErrorBoundary.tsx +++ b/src/components/ErrorBoundary/ErrorBoundary.tsx @@ -33,11 +33,16 @@ export default class ErrorBoundary extends Component { } componentDidCatch(error: Error, info: unknown) { - Sentry.withScope((scope) => { - scope.setExtras(info as Extras); - const eventId = Sentry.captureException(error); - this.setState({ eventId }); - }); + if ( + process.env.NODE_ENV === "production" && + window.jujuDashboardConfig?.analyticsEnabled + ) { + Sentry.withScope((scope) => { + scope.setExtras(info as Extras); + const eventId = Sentry.captureException(error); + this.setState({ eventId }); + }); + } } render() { diff --git a/src/index.tsx b/src/index.tsx index 5d608d0a8..654bfae36 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -32,7 +32,10 @@ if (!window.process) { window.process = process; } -if (process.env.NODE_ENV === "production") { +if ( + process.env.NODE_ENV === "production" && + window.jujuDashboardConfig?.analyticsEnabled +) { Sentry.init({ dsn: "https://5f679e274f34464194e9592a91ed65d4@sentry.is.canonical.com//29", }); @@ -131,7 +134,7 @@ function bootstrap() { } } - if (process.env.NODE_ENV === "production") { + if (process.env.NODE_ENV === "production" && config.analyticsEnabled) { Sentry.setTag("isJuju", config.isJuju); } diff --git a/src/store/middleware/model-poller.ts b/src/store/middleware/model-poller.ts index 090d7c062..8619d2307 100644 --- a/src/store/middleware/model-poller.ts +++ b/src/store/middleware/model-poller.ts @@ -106,7 +106,10 @@ export const modelPollerMiddleware: Middleware< // XXX Now that we can register multiple controllers this needs // to be sent per controller. - if (process.env.NODE_ENV === "production") { + if ( + process.env.NODE_ENV === "production" && + window.jujuDashboardConfig?.analyticsEnabled + ) { Sentry.setTag("jujuVersion", conn.info.serverVersion); }