Bladeren bron

refactor sentry config

Abhinav 3 jaren geleden
bovenliggende
commit
509750ff8f
4 gewijzigde bestanden met toevoegingen van 42 en 13 verwijderingen
  1. 12 0
      configUtil.js
  2. 6 3
      next.config.js
  3. 12 6
      sentry.client.config.js
  4. 12 4
      sentry.server.config.js

+ 12 - 0
configUtil.js

@@ -50,4 +50,16 @@ module.exports = {
             cwd: __dirname,
             encoding: 'utf8',
         }),
+
+    getSentryDSN: () =>
+        process.env.NEXT_PUBLIC_SENTRY_DSN ??
+        'https://860186db60c54c7fbacfe255124958e8@errors.ente.io/4',
+
+    getSentryENV: () => process.env.NEXT_PUBLIC_SENTRY_ENV ?? 'development',
+
+    getSentryRelease: () => process.env.SENTRY_RELEASE,
+
+    isSentryEnabled: () =>
+        process.env.SENTRY_ENABLED ??
+        (process.env.NEXT_PUBLIC_SENTRY_ENV ?? 'development') !== 'development',
 };

+ 6 - 3
next.config.js

@@ -14,15 +14,18 @@ const {
     CSP_DIRECTIVES,
     WORKBOX_CONFIG,
     ALL_ROUTES,
+    isSentryEnabled,
 } = require('./configUtil');
 
-const gitSha = getGitSha();
+const GIT_SHA = getGitSha();
+
+const SENTRY_ENABLED = isSentryEnabled();
 
 module.exports = withSentryConfig(
     withWorkbox(
         withBundleAnalyzer({
             env: {
-                SENTRY_RELEASE: gitSha,
+                SENTRY_RELEASE: GIT_SHA,
             },
             workbox: WORKBOX_CONFIG,
 
@@ -48,5 +51,5 @@ module.exports = withSentryConfig(
             },
         })
     ),
-    { release: gitSha }
+    { release: GIT_SHA, dryRun: !SENTRY_ENABLED }
 );

+ 12 - 6
sentry.client.config.js

@@ -1,18 +1,24 @@
 import * as Sentry from '@sentry/nextjs';
 import { getSentryTunnelUrl } from 'utils/common/apiUtil';
 import { getUserAnonymizedID } from 'utils/user';
+import {
+    getSentryDSN,
+    getSentryENV,
+    getSentryRelease,
+    isSentryEnabled,
+} from './configUtil';
 
-const SENTRY_DSN =
-    process.env.NEXT_PUBLIC_SENTRY_DSN ??
-    'https://860186db60c54c7fbacfe255124958e8@errors.ente.io/4';
-const SENTRY_ENV = process.env.NEXT_PUBLIC_SENTRY_ENV ?? 'development';
+const SENTRY_DSN = getSentryDSN();
+const SENTRY_ENV = getSentryENV();
+const SENTRY_RELEASE = getSentryRelease();
+const ENABLED = isSentryEnabled();
 
 Sentry.setUser({ id: getUserAnonymizedID() });
 Sentry.init({
     dsn: SENTRY_DSN,
-    enabled: SENTRY_ENV !== 'development',
+    enabled: ENABLED,
     environment: SENTRY_ENV,
-    release: process.env.SENTRY_RELEASE,
+    release: SENTRY_RELEASE,
     attachStacktrace: true,
     autoSessionTracking: false,
     tunnel: getSentryTunnelUrl(),

+ 12 - 4
sentry.server.config.js

@@ -1,12 +1,20 @@
 import * as Sentry from '@sentry/nextjs';
+import {
+    getSentryDSN,
+    getSentryENV,
+    getSentryRelease,
+    isSentryEnabled,
+} from './configUtil';
 
-const SENTRY_DSN = process.env.NEXT_PUBLIC_SENTRY_DSN ?? 'https://860186db60c54c7fbacfe255124958e8@errors.ente.io/4';
-const SENTRY_ENV = process.env.NEXT_PUBLIC_SENTRY_ENV ?? 'development';
+const SENTRY_DSN = getSentryDSN();
+const SENTRY_ENV = getSentryENV();
+const SENTRY_RELEASE = getSentryRelease();
+const ENABLED = isSentryEnabled();
 
 Sentry.init({
     dsn: SENTRY_DSN,
-    enabled: SENTRY_ENV !== 'development',
+    enabled: ENABLED,
     environment: SENTRY_ENV,
-    release: process.env.SENTRY_RELEASE,
+    release: SENTRY_RELEASE,
     autoSessionTracking: false,
 });