From 1aec53311d2c20350148d3a8403715315ffef91b Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sun, 9 Jan 2022 13:50:52 +0530 Subject: [PATCH 1/3] rename sentry is environement variable to make it accessible in browser --- sentryConfigUtil.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sentryConfigUtil.js b/sentryConfigUtil.js index d8f5da7a3..1b19f2f6b 100644 --- a/sentryConfigUtil.js +++ b/sentryConfigUtil.js @@ -1,6 +1,6 @@ -module.exports.isSentryEnabled = () => { - if (process.env.SENTRY_ENABLED) { - return process.env.SENTRY_ENABLED === 'yes'; +module.exports.getIsSentryEnabled = () => { + if (process.env.NEXT_PUBLIC_IS_SENTRY_ENABLED) { + return process.env.NEXT_PUBLIC_IS_SENTRY_ENABLED === 'yes'; } else { if (process.env.NEXT_PUBLIC_SENTRY_ENV) { return process.env.NEXT_PUBLIC_SENTRY_ENV !== 'development'; From 4cdc93e3453c02dcf872566e34762d3e2967146b Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sun, 9 Jan 2022 13:51:47 +0530 Subject: [PATCH 2/3] renamed sentry constants to follow the global convention --- configUtil.js | 4 ++-- next.config.js | 9 ++++++--- sentry.client.config.js | 6 +++--- sentry.server.config.js | 6 +++--- src/constants/sentry/index.ts | 2 +- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/configUtil.js b/configUtil.js index e0941ea61..438114a99 100644 --- a/configUtil.js +++ b/configUtil.js @@ -1,5 +1,5 @@ const cp = require('child_process'); -const { isSentryEnabled } = require('./sentryConfigUtil'); +const { getIsSentryEnabled } = require('./sentryConfigUtil'); module.exports = { COOP_COEP_HEADERS: { @@ -51,5 +51,5 @@ module.exports = { cwd: __dirname, encoding: 'utf8', }), - isSentryEnabled: isSentryEnabled, + getIsSentryEnabled: getIsSentryEnabled, }; diff --git a/next.config.js b/next.config.js index ee9744388..1413dd1a9 100644 --- a/next.config.js +++ b/next.config.js @@ -14,12 +14,12 @@ const { CSP_DIRECTIVES, WORKBOX_CONFIG, ALL_ROUTES, - isSentryEnabled, + getIsSentryEnabled, } = require('./configUtil'); const GIT_SHA = getGitSha(); -const SENTRY_ENABLED = isSentryEnabled(); +const IS_SENTRY_ENABLED = getIsSentryEnabled(); module.exports = withSentryConfig( withWorkbox( @@ -51,5 +51,8 @@ module.exports = withSentryConfig( }, }) ), - { release: GIT_SHA, dryRun: !SENTRY_ENABLED } + { + release: GIT_SHA, + dryRun: !IS_SENTRY_ENABLED, + } ); diff --git a/sentry.client.config.js b/sentry.client.config.js index 4b39522c0..09e2fe20d 100644 --- a/sentry.client.config.js +++ b/sentry.client.config.js @@ -5,18 +5,18 @@ import { getSentryDSN, getSentryENV, getSentryRelease, - isSentryEnabled, + getIsSentryEnabled, } from 'constants/sentry'; const SENTRY_DSN = getSentryDSN(); const SENTRY_ENV = getSentryENV(); const SENTRY_RELEASE = getSentryRelease(); -const ENABLED = isSentryEnabled(); +const IS_ENABLED = getIsSentryEnabled(); Sentry.setUser({ id: getUserAnonymizedID() }); Sentry.init({ dsn: SENTRY_DSN, - enabled: ENABLED, + enabled: IS_ENABLED, environment: SENTRY_ENV, release: SENTRY_RELEASE, attachStacktrace: true, diff --git a/sentry.server.config.js b/sentry.server.config.js index 62b0029c0..5d8714c99 100644 --- a/sentry.server.config.js +++ b/sentry.server.config.js @@ -3,17 +3,17 @@ import { getSentryDSN, getSentryENV, getSentryRelease, - isSentryEnabled, + getIsSentryEnabled, } from 'constants/sentry'; const SENTRY_DSN = getSentryDSN(); const SENTRY_ENV = getSentryENV(); const SENTRY_RELEASE = getSentryRelease(); -const ENABLED = isSentryEnabled(); +const IS_ENABLED = getIsSentryEnabled(); Sentry.init({ dsn: SENTRY_DSN, - enabled: ENABLED, + enabled: IS_ENABLED, environment: SENTRY_ENV, release: SENTRY_RELEASE, autoSessionTracking: false, diff --git a/src/constants/sentry/index.ts b/src/constants/sentry/index.ts index 79aec9795..5ccfcebe1 100644 --- a/src/constants/sentry/index.ts +++ b/src/constants/sentry/index.ts @@ -7,4 +7,4 @@ export const getSentryENV = () => export const getSentryRelease = () => process.env.SENTRY_RELEASE; -export { isSentryEnabled } from '../../../sentryConfigUtil'; +export { getIsSentryEnabled } from '../../../sentryConfigUtil'; From 4b14427f360020f46bce0e401151bd5cf81bbc58 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sun, 9 Jan 2022 13:52:57 +0530 Subject: [PATCH 3/3] disable sentry if next phase is PHASE_DEVELOPMENT_SERVER --- next.config.js | 70 ++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/next.config.js b/next.config.js index 1413dd1a9..056b654ad 100644 --- a/next.config.js +++ b/next.config.js @@ -4,6 +4,7 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({ const withWorkbox = require('@ente-io/next-with-workbox'); const { withSentryConfig } = require('@sentry/nextjs'); +const { PHASE_DEVELOPMENT_SERVER } = require('next/constants'); const { getGitSha, @@ -21,38 +22,39 @@ const GIT_SHA = getGitSha(); const IS_SENTRY_ENABLED = getIsSentryEnabled(); -module.exports = withSentryConfig( - withWorkbox( - withBundleAnalyzer({ - env: { - SENTRY_RELEASE: GIT_SHA, - }, - workbox: WORKBOX_CONFIG, +module.exports = (phase) => + withSentryConfig( + withWorkbox( + withBundleAnalyzer({ + env: { + SENTRY_RELEASE: GIT_SHA, + }, + workbox: WORKBOX_CONFIG, - headers() { - return [ - { - // Apply these headers to all routes in your application.... - source: ALL_ROUTES, - headers: convertToNextHeaderFormat({ - ...COOP_COEP_HEADERS, - ...WEB_SECURITY_HEADERS, - ...buildCSPHeader(CSP_DIRECTIVES), - }), - }, - ]; - }, - // https://dev.to/marcinwosinek/how-to-add-resolve-fallback-to-webpack-5-in-nextjs-10-i6j - webpack: (config, { isServer }) => { - if (!isServer) { - config.resolve.fallback.fs = false; - } - return config; - }, - }) - ), - { - release: GIT_SHA, - dryRun: !IS_SENTRY_ENABLED, - } -); + headers() { + return [ + { + // Apply these headers to all routes in your application.... + source: ALL_ROUTES, + headers: convertToNextHeaderFormat({ + ...COOP_COEP_HEADERS, + ...WEB_SECURITY_HEADERS, + ...buildCSPHeader(CSP_DIRECTIVES), + }), + }, + ]; + }, + // https://dev.to/marcinwosinek/how-to-add-resolve-fallback-to-webpack-5-in-nextjs-10-i6j + webpack: (config, { isServer }) => { + if (!isServer) { + config.resolve.fallback.fs = false; + } + return config; + }, + }) + ), + { + release: GIT_SHA, + dryRun: phase === PHASE_DEVELOPMENT_SERVER || !IS_SENTRY_ENABLED, + } + );