This commit is contained in:
Manav Rathi 2024-02-10 17:18:20 +05:30
parent 977da14e70
commit 0119cddd50
10 changed files with 40 additions and 83 deletions

View file

@ -20,9 +20,10 @@
#
# A development build behaves differently in some aspects:
#
# 1. Logs go to the browser console (in addition to the log file).
# 1. Logs go to the browser console (in addition to the log file), and there is
# additional logging too.
#
# 2. Sentry crash reports go to a separate project.
# 2. Crash reports go to a separate "development" environment in Sentry.
#
# 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

@ -6,12 +6,6 @@ export enum APPS {
ALBUMS = 'ALBUMS',
}
export enum APP_ENV {
DEVELOPMENT = 'development',
PRODUCTION = 'production',
TEST = 'test',
}
export const CLIENT_PACKAGE_NAMES = new Map([
[APPS.ALBUMS, 'io.ente.albums.web'],
[APPS.PHOTOS, 'io.ente.photos.web'],

View file

@ -1,8 +1,3 @@
import { APP_ENV } from './constants';
export const getAppEnv = () =>
process.env.NEXT_PUBLIC_APP_ENV ?? APP_ENV.PRODUCTION;
export const isDisableSentryFlagSet = () => {
return process.env.NEXT_PUBLIC_DISABLE_SENTRY === 'true';
};

View file

@ -1,9 +1,8 @@
import isElectron from 'is-electron';
import { logError } from '@ente/shared/sentry';
import { getAppEnv } from '../apps/env';
import { APP_ENV } from '../apps/constants';
import { formatLog, logWeb } from './web';
import { WorkerSafeElectronService } from '../electron/service';
import { isDevBuild } from '../network/api';
export const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB
export const MAX_LOG_LINES = 1000;
@ -14,7 +13,7 @@ export function addLogLine(
) {
try {
const completeLog = [log, ...optionalParams].join(' ');
if (getAppEnv() === APP_ENV.DEVELOPMENT) {
if (isDevBuild()) {
console.log(completeLog);
}
if (isElectron()) {
@ -29,7 +28,7 @@ export function addLogLine(
}
export const addLocalLog = (getLog: () => string) => {
if (getAppEnv() === APP_ENV.DEVELOPMENT) {
if (isDevBuild()) {
console.log(
formatLog({
logLine: getLog(),

View file

@ -75,15 +75,15 @@ export const getFamilyPortalURL = () => {
};
/**
* A build is considered as a development build if the NODE_ENV environment
* variable is set to 'development'.
* A build is considered as a development build if either the NODE_ENV is
* environment variable is set to 'development'.
*
* This automatically happens when we run `yarn dev:foo`, but we can also
* explictly set it to development before invoking the build. From Next.js docs:
* NODE_ENV is automatically set to 'development' when we run `yarn dev`. From
* Next.js docs:
*
* > If the environment variable NODE_ENV is unassigned, Next.js
* automatically assigns development when running the `next dev` command,
* or production for all other commands.
* > If the environment variable NODE_ENV is unassigned, Next.js automatically
* assigns development when running the `next dev` command, or production for
* all other commands.
*/
export const isDevBuild = () => {
return process.env.NODE_ENV === 'development';

View file

@ -42,8 +42,8 @@ module.exports = (phase) =>
'@mui/icons-material',
],
env: {
// Sentry reads this env var to set the "release" value.
SENTRY_RELEASE: GIT_SHA,
NEXT_PUBLIC_IS_TEST_APP: process.env.IS_TEST_RELEASE || 'false',
},
// https://dev.to/marcinwosinek/how-to-add-resolve-fallback-to-webpack-5-in-nextjs-10-i6j

View file

@ -2,44 +2,30 @@ 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 { getIsSentryEnabled } from '@ente/shared/sentry/utils';
import { getAppEnv, getSentryRelease } from '@ente/shared/apps/env';
export const setupSentry = async (dsn: string) => {
const HAS_OPTED_OUT_OF_CRASH_REPORTING =
runningInBrowser() && getHasOptedOutOfCrashReports();
const optedOut = runningInBrowser() && getHasOptedOutOfCrashReports();
if (optedOut) return;
if (!HAS_OPTED_OUT_OF_CRASH_REPORTING) {
const APP_ENV = getAppEnv();
const IS_ENABLED = getIsSentryEnabled();
const SENTRY_RELEASE = getSentryRelease();
Sentry.init({
dsn,
environment: process.env.NODE_ENV,
attachStacktrace: true,
autoSessionTracking: false,
tunnel: 'https://sentry-reporter.ente.io',
beforeSend(event) {
event.request = event.request || {};
const currentURL = new URL(document.location.href);
currentURL.hash = '';
event.request.url = currentURL.href;
return event;
},
integrations: function (i) {
return i.filter(function (i) {
return i.name !== 'Breadcrumbs';
});
},
});
Sentry.init({
dsn,
enabled: IS_ENABLED,
environment: APP_ENV,
release: SENTRY_RELEASE,
attachStacktrace: true,
autoSessionTracking: false,
tunnel: 'https://sentry-reporter.ente.io',
beforeSend(event) {
event.request = event.request || {};
const currentURL = new URL(document.location.href);
currentURL.hash = '';
event.request.url = currentURL.href;
return event;
},
integrations: function (i) {
return i.filter(function (i) {
return i.name !== 'Breadcrumbs';
});
},
// ...
// Note: if you want to override the automatic release value, do not set a
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
// that it will also get attached to your source maps
});
Sentry.setUser({ id: await getSentryUserID() });
}
Sentry.setUser({ id: await getSentryUserID() });
};

View file

@ -4,11 +4,10 @@ import {
setLocalSentryUserID,
} from '@ente/shared/storage/localStorage/helpers';
import isElectron from 'is-electron';
import { getAppEnv } from '@ente/shared/apps/env';
import { APP_ENV } from '@ente/shared/apps/constants';
import { isDisableSentryFlagSet } from '@ente/shared/apps/env';
import { ApiError } from '../error';
import { HttpStatusCode } from 'axios';
import { isDevBuild } from '../network/api';
export async function getSentryUserID() {
if (isElectron()) {
@ -49,7 +48,6 @@ export function isErrorUnnecessaryForSentry(error: any) {
}
export const getIsSentryEnabled = () => {
const isAppENVDevelopment = getAppEnv() === APP_ENV.DEVELOPMENT;
const isSentryDisabled = isDisableSentryFlagSet();
return !isAppENVDevelopment && !isSentryDisabled;
return !isDevBuild() && !isSentryDisabled;
};

View file

@ -15,16 +15,6 @@ set -o xtrace
rm -rf out
# Cloudflare Pages has two separate environments - Production and Preview.
#
# Each of these have their separate environment variables. However, we need to
# deploy multiple production apps - so while for the "photos-release" branch
# (which corresponds to Cloudflare's "Production" environment) can have separate
# environment variables, the rest of the production deployments share the same
# environment variables (those that are set for the Preview environment in CF).
#
# So we instead tune environment variables for specific deployments here.
if test "$CF_PAGES_BRANCH" = "photos-release"; then
yarn export:photos
cp -R apps/photos/out .
@ -32,10 +22,7 @@ elif test "$CF_PAGES_BRANCH" = "auth-release"; then
yarn export:auth
cp -R apps/auth/out .
else
# Apart from the named branches, everything else gets treated as a
# development deployment.
export NODE_ENV=development
# Also, we connect all of them to the dev APIs.
# Apart from the named branches, everything else connects to the dev APIs.
export NEXT_PUBLIC_ENTE_ENDPOINT=https://dev-api.ente.io
export NEXT_PUBLIC_ENTE_ALBUM_ENDPOINT=https://dev-albums.ente.io

View file

@ -24,10 +24,7 @@
"NEXT_PUBLIC_ENTE_PAYMENT_ENDPOINT",
"NEXT_PUBLIC_ENTE_ALBUM_ENDPOINT",
"NEXT_PUBLIC_ENTE_FAMILY_PORTAL_ENDPOINT",
"NEXT_PUBLIC_ENTE_WEB_ENDPOINT",
"NEXT_PUBLIC_IS_TEST_APP",
"NODE_ENV",
"SENTRY_RELEASE",
"SENTRY_AUTH_TOKEN"
"SENTRY_RELEASE"
]
}