浏览代码

Don't initialize Sentry on dev builds

Manav Rathi 1 年之前
父节点
当前提交
bf70857a41
共有 2 个文件被更改,包括 13 次插入6 次删除
  1. 4 4
      apps/photos/.env.development
  2. 9 2
      packages/shared/sentry/config/sentry.config.base.ts

+ 4 - 4
apps/photos/.env.development

@@ -20,10 +20,10 @@
 #
 # A development build behaves differently in some aspects:
 #
-# 1. Logs go to the browser console (in addition to the log file), and there is
-#    additional logging too.
-#
-# 2. Crash reports go to a separate "development" environment in Sentry.
+# - Logs go to the browser console (in addition to the log file)
+# - There is some additional logging
+# - Sentry is not initialized
+# - ... (search for isDevBuild to see all impacts)
 #
 # Note that even in development build, the app still connects to the production
 # APIs by default (can be customized using the env vars below). This is usually

+ 9 - 2
packages/shared/sentry/config/sentry.config.base.ts

@@ -2,10 +2,14 @@ import * as Sentry from '@sentry/nextjs';
 import { getSentryUserID } from '@ente/shared/sentry/utils';
 import { runningInBrowser } from '@ente/shared/platform';
 import { getHasOptedOutOfCrashReports } from '@ente/shared/storage/localStorage/helpers';
+import { isDevBuild } from '@ente/shared/network/api';
 
 export const initSentry = async (dsn: string) => {
-    const optedOut = runningInBrowser() && getHasOptedOutOfCrashReports();
-    if (optedOut) return;
+    // Don't initialize Sentry on dev builds
+    if (isDevBuild) return;
+
+    // Don't initialize Sentry if the user has opted out of crash reporting
+    if (optedOut()) return;
 
     // [Note: Specifying the Sentry release]
     //
@@ -51,3 +55,6 @@ export const initSentry = async (dsn: string) => {
 
     Sentry.setUser({ id: await getSentryUserID() });
 };
+
+/** Return true if the user has opted out of crash reporting */
+const optedOut = () => runningInBrowser() && getHasOptedOutOfCrashReports();