Don't initialize Sentry on dev builds

This commit is contained in:
Manav Rathi 2024-02-13 12:11:14 +05:30
parent 8a769ea08b
commit bf70857a41
2 changed files with 13 additions and 6 deletions

View file

@ -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

View file

@ -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();