Skip to content

Commit

Permalink
feat: Enable Sentry only if analyticsEnabled is true (canonical#1673)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-cucu authored Dec 5, 2023
1 parent e6b2be0 commit 5d01b93
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
15 changes: 10 additions & 5 deletions src/components/ErrorBoundary/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ export default class ErrorBoundary extends Component<Props, State> {
}

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() {
Expand Down
7 changes: 5 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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://[email protected]//29",
});
Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 4 additions & 1 deletion src/store/middleware/model-poller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 5d01b93

Please sign in to comment.