From f0018b0e963347314d4da10b0e06b43b20549b79 Mon Sep 17 00:00:00 2001 From: Niraj Date: Mon, 2 Dec 2024 12:49:44 +0545 Subject: [PATCH 1/2] feat: enable sentry init only when the enable flag is set --- .../workflows/build-and-deploy-test-stack.yml | 2 +- govtool/frontend/.env.example | 3 +- govtool/frontend/Dockerfile.qovery | 1 + govtool/frontend/src/main.tsx | 46 ++++++++++--------- tests/test-infrastructure/.env.example | 3 +- 5 files changed, 30 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build-and-deploy-test-stack.yml b/.github/workflows/build-and-deploy-test-stack.yml index 522c723b8..aa4d66626 100644 --- a/.github/workflows/build-and-deploy-test-stack.yml +++ b/.github/workflows/build-and-deploy-test-stack.yml @@ -61,7 +61,7 @@ jobs: cd $DEST_DIR/tests/test-infrastructure ./build-and-deploy.sh update-images yes | docker system prune -f || echo "Ignoring system prune eror" - envs: GOVTOOL_TAG, GRAFANA_ADMIN_PASSWORD, GRAFANA_SLACK_RECIPIENT, GRAFANA_SLACK_OAUTH_TOKEN, SENTRY_DSN_BACKEND, GTM_ID, NPMRC_TOKEN, SENTRY_DSN_FRONTEND, PIPELINE_URL, USERSNAP_SPACE_API_KEY, APP_ENV, PDF_API_URL, KUBER_API_KEY, IPFS_GATEWAY, IPFS_PROJECT_ID + envs: GOVTOOL_TAG, GRAFANA_ADMIN_PASSWORD, GRAFANA_SLACK_RECIPIENT, GRAFANA_SLACK_OAUTH_TOKEN, SENTRY_DSN_BACKEND, GTM_ID, NPMRC_TOKEN, SENTRY_DSN_FRONTEND, PIPELINE_URL, USERSNAP_SPACE_API_KEY, APP_ENV, PDF_API_URL, KUBER_API_KEY, IPFS_GATEWAY, IPFS_PROJECT_ID, IS_SENTRY_ENABLED env: GOVTOOL_TAG: ${{ github.sha }} GRAFANA_ADMIN_PASSWORD: ${{ secrets.GRAFANA_ADMIN_PASSWORD }} diff --git a/govtool/frontend/.env.example b/govtool/frontend/.env.example index 2489d65a0..5ac52ef6c 100644 --- a/govtool/frontend/.env.example +++ b/govtool/frontend/.env.example @@ -9,4 +9,5 @@ VITE_USERSNAP_SPACE_API_KEY="" VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED='true' VITE_PDF_API_URL="" VITE_IPFS_GATEWAY="" -VITE_IPFS_PROJECT_ID="" \ No newline at end of file +VITE_IPFS_PROJECT_ID="" +VITE_IS_SENTRY_ENABLED=false diff --git a/govtool/frontend/Dockerfile.qovery b/govtool/frontend/Dockerfile.qovery index 6ccba937d..415120984 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_IS_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..3b54a47fe 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_IS_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( diff --git a/tests/test-infrastructure/.env.example b/tests/test-infrastructure/.env.example index 82a24d40a..6596a0ee2 100644 --- a/tests/test-infrastructure/.env.example +++ b/tests/test-infrastructure/.env.example @@ -9,4 +9,5 @@ APP_ENV=test PDF_API_URL= KUBER_API_KEY= IPFS_GATEWAY="" -IPFS_PROJECT_ID="" \ No newline at end of file +IPFS_PROJECT_ID="" +IS_SENTRY_ENABLED=false \ No newline at end of file From c35033b3f91aebc5c7854c89e8278cebcd2ac6d5 Mon Sep 17 00:00:00 2001 From: Niraj Date: Mon, 2 Dec 2024 12:50:03 +0545 Subject: [PATCH 2/2] chore: add missing sentryenv on backend config --- tests/test-infrastructure/configs_template/backend_config.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test-infrastructure/configs_template/backend_config.json b/tests/test-infrastructure/configs_template/backend_config.json index 2079085a2..753047de5 100644 --- a/tests/test-infrastructure/configs_template/backend_config.json +++ b/tests/test-infrastructure/configs_template/backend_config.json @@ -9,5 +9,6 @@ "port" : 8080, "host" : "0.0.0.0", "cachedurationseconds": 20, - "sentrydsn": "${SENTRY_DSN_BACKEND:-https://username:password@senty.host/id}" + "sentrydsn": "${SENTRY_DSN_BACKEND:-https://username:password@senty.host/id}", + "sentryenv": "test" } \ No newline at end of file