ソースを参照

refactor sentry config

Abhinav 3 年 前
コミット
509750ff8f
4 ファイル変更42 行追加13 行削除
  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,
             cwd: __dirname,
             encoding: 'utf8',
             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,
     CSP_DIRECTIVES,
     WORKBOX_CONFIG,
     WORKBOX_CONFIG,
     ALL_ROUTES,
     ALL_ROUTES,
+    isSentryEnabled,
 } = require('./configUtil');
 } = require('./configUtil');
 
 
-const gitSha = getGitSha();
+const GIT_SHA = getGitSha();
+
+const SENTRY_ENABLED = isSentryEnabled();
 
 
 module.exports = withSentryConfig(
 module.exports = withSentryConfig(
     withWorkbox(
     withWorkbox(
         withBundleAnalyzer({
         withBundleAnalyzer({
             env: {
             env: {
-                SENTRY_RELEASE: gitSha,
+                SENTRY_RELEASE: GIT_SHA,
             },
             },
             workbox: WORKBOX_CONFIG,
             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 * as Sentry from '@sentry/nextjs';
 import { getSentryTunnelUrl } from 'utils/common/apiUtil';
 import { getSentryTunnelUrl } from 'utils/common/apiUtil';
 import { getUserAnonymizedID } from 'utils/user';
 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.setUser({ id: getUserAnonymizedID() });
 Sentry.init({
 Sentry.init({
     dsn: SENTRY_DSN,
     dsn: SENTRY_DSN,
-    enabled: SENTRY_ENV !== 'development',
+    enabled: ENABLED,
     environment: SENTRY_ENV,
     environment: SENTRY_ENV,
-    release: process.env.SENTRY_RELEASE,
+    release: SENTRY_RELEASE,
     attachStacktrace: true,
     attachStacktrace: true,
     autoSessionTracking: false,
     autoSessionTracking: false,
     tunnel: getSentryTunnelUrl(),
     tunnel: getSentryTunnelUrl(),

+ 12 - 4
sentry.server.config.js

@@ -1,12 +1,20 @@
 import * as Sentry from '@sentry/nextjs';
 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({
 Sentry.init({
     dsn: SENTRY_DSN,
     dsn: SENTRY_DSN,
-    enabled: SENTRY_ENV !== 'development',
+    enabled: ENABLED,
     environment: SENTRY_ENV,
     environment: SENTRY_ENV,
-    release: process.env.SENTRY_RELEASE,
+    release: SENTRY_RELEASE,
     autoSessionTracking: false,
     autoSessionTracking: false,
 });
 });