From 6dcda0d2dcec5c6e394e42336f924ca18249f080 Mon Sep 17 00:00:00 2001 From: Niraj Date: Mon, 2 Dec 2024 12:49:44 +0545 Subject: [PATCH] feat: enable sentry init only when the enable flag is set --- govtool/frontend/.env.example | 1 + govtool/frontend/Dockerfile.qovery | 1 + govtool/frontend/src/main.tsx | 46 ++++++++++++++++-------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/govtool/frontend/.env.example b/govtool/frontend/.env.example index 5fbb1a97f..c604eab6d 100644 --- a/govtool/frontend/.env.example +++ b/govtool/frontend/.env.example @@ -8,3 +8,4 @@ VITE_IS_DEV=true VITE_USERSNAP_SPACE_API_KEY="" VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED='true' VITE_PDF_API_URL="" +VITE_SENTRY_ENABLED=false diff --git a/govtool/frontend/Dockerfile.qovery b/govtool/frontend/Dockerfile.qovery index ddc6c1288..2d090fef7 100644 --- a/govtool/frontend/Dockerfile.qovery +++ b/govtool/frontend/Dockerfile.qovery @@ -1,6 +1,7 @@ FROM node:20.18.1-alpine as builder ARG VITE_APP_ENV='beta' +ARG VITE_SENTRY_ENABLED='false' ARG VITE_BASE_URL ARG VITE_METADATA_API_URL ARG VITE_GTM_ID diff --git a/govtool/frontend/src/main.tsx b/govtool/frontend/src/main.tsx index 76f6ff419..ae79b0dd0 100644 --- a/govtool/frontend/src/main.tsx +++ b/govtool/frontend/src/main.tsx @@ -24,28 +24,30 @@ const tagManagerArgs = { TagManager.initialize(tagManagerArgs); -Sentry.init({ - dsn: import.meta.env.VITE_SENTRY_DSN, - environment: import.meta.env.VITE_APP_ENV, - release: version, - integrations: [ - Sentry.browserTracingIntegration(), - Sentry.replayIntegration(), - ], - tracesSampleRate: 1.0, - replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1.0, - beforeSend(event) { - window.dataLayer = window.dataLayer || []; - window.dataLayer.push({ - event: "sentryEvent", - sentryEventId: event?.event_id || "default_event_id", - sentryErrorMessage: - event?.exception?.values?.[0]?.value || "Unknown Error", - }); - return event; - }, -}); +if (import.meta.env.VITE_SENTRY_ENABLED) { + Sentry.init({ + dsn: import.meta.env.VITE_SENTRY_DSN, + environment: import.meta.env.VITE_APP_ENV, + release: version, + integrations: [ + Sentry.browserTracingIntegration(), + Sentry.replayIntegration(), + ], + tracesSampleRate: 1.0, + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0, + beforeSend(event) { + window.dataLayer = window.dataLayer || []; + window.dataLayer.push({ + event: "sentryEvent", + sentryEventId: event?.event_id || "default_event_id", + sentryErrorMessage: + event?.exception?.values?.[0]?.value || "Unknown Error", + }); + return event; + }, + }); +} ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(