瀏覽代碼

Include the git SHA in the logs

Manav Rathi 1 年之前
父節點
當前提交
39034474ba

+ 6 - 11
apps/auth/src/pages/_app.tsx

@@ -5,7 +5,7 @@ import { t } from 'i18next';
 import { useRouter } from 'next/router';
 import { Overlay } from '@ente/shared/components/Container';
 import EnteSpinner from '@ente/shared/components/EnteSpinner';
-import { getData, LS_KEYS } from '@ente/shared/storage/localStorage';
+import { LS_KEYS } from '@ente/shared/storage/localStorage';
 import HTTPService from '@ente/shared/network/HTTPService';
 import Head from 'next/head';
 import LoadingBar from 'react-top-loading-bar';
@@ -17,8 +17,10 @@ import {
     DialogBoxAttributesV2,
     SetDialogBoxAttributesV2,
 } from '@ente/shared/components/DialogBoxV2/types';
-import { addLogLine } from '@ente/shared/logging';
-import { clearLogsIfLocalStorageLimitExceeded } from '@ente/shared/logging/web';
+import {
+    clearLogsIfLocalStorageLimitExceeded,
+    logStartupMessage,
+} from '@ente/shared/logging/web';
 
 import { CacheProvider } from '@emotion/react';
 import {
@@ -31,8 +33,6 @@ import createEmotionCache from '@ente/shared/themes/createEmotionCache';
 import { THEME_COLOR } from '@ente/shared/themes/constants';
 import { SetTheme } from '@ente/shared/themes/types';
 import { setupI18n } from '@ente/shared/i18n';
-import { getSentryUserID } from '@ente/shared/sentry/utils';
-import { User } from '@ente/shared/user/types';
 import { useLocalState } from '@ente/shared/hooks/useLocalState';
 import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
 import { getTheme } from '@ente/shared/themes';
@@ -87,12 +87,7 @@ export default function App(props: EnteAppProps) {
         });
         // setup logging
         clearLogsIfLocalStorageLimitExceeded();
-        const main = async () => {
-            addLogLine(`userID: ${(getData(LS_KEYS.USER) as User)?.id}`);
-            addLogLine(`sentryID: ${await getSentryUserID()}`);
-            addLogLine(`sentry release: ${process.env.SENTRY_RELEASE}`);
-        };
-        main();
+        logStartupMessage();
     }, []);
 
     const setUserOnline = () => setOffline(false);

+ 5 - 9
apps/photos/src/pages/_app.tsx

@@ -39,7 +39,10 @@ import {
 } from 'services/userService';
 import { CustomError } from '@ente/shared/error';
 import { addLogLine } from '@ente/shared/logging';
-import { clearLogsIfLocalStorageLimitExceeded } from '@ente/shared/logging/web';
+import {
+    clearLogsIfLocalStorageLimitExceeded,
+    logStartupMessage,
+} from '@ente/shared/logging/web';
 import isElectron from 'is-electron';
 import ElectronAPIs from '@ente/shared/electron';
 import {
@@ -71,8 +74,6 @@ import createEmotionCache from '@ente/shared/themes/createEmotionCache';
 import { THEME_COLOR } from '@ente/shared/themes/constants';
 import { SetTheme } from '@ente/shared/themes/types';
 import { setupI18n } from '@ente/shared/i18n';
-import { getSentryUserID } from '@ente/shared/sentry/utils';
-import { User } from '@ente/shared/user/types';
 import { useLocalState } from '@ente/shared/hooks/useLocalState';
 import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
 import { getTheme } from '@ente/shared/themes';
@@ -168,12 +169,7 @@ export default function App(props: EnteAppProps) {
         });
         // setup logging
         clearLogsIfLocalStorageLimitExceeded();
-        const main = async () => {
-            addLogLine(`userID: ${(getData(LS_KEYS.USER) as User)?.id}`);
-            addLogLine(`sentryID: ${await getSentryUserID()}`);
-            addLogLine(`sentry release: ${process.env.SENTRY_RELEASE}`);
-        };
-        main();
+        logStartupMessage();
     }, []);
 
     useEffect(() => {

+ 2 - 2
packages/shared/logging/index.ts

@@ -13,7 +13,7 @@ export function addLogLine(
 ) {
     try {
         const completeLog = [log, ...optionalParams].join(' ');
-        if (isDevBuild()) {
+        if (isDevBuild) {
             console.log(completeLog);
         }
         if (isElectron()) {
@@ -28,7 +28,7 @@ export function addLogLine(
 }
 
 export const addLocalLog = (getLog: () => string) => {
-    if (isDevBuild()) {
+    if (isDevBuild) {
         console.log(
             formatLog({
                 logLine: getLog(),

+ 9 - 0
packages/shared/logging/web.ts

@@ -8,6 +8,9 @@ import {
     setData,
 } from '@ente/shared/storage/localStorage';
 import { ElectronFile } from '../upload/types';
+import { addLogLine } from '.';
+import { getSentryUserID } from '../sentry/utils';
+import type { User } from '../user/types';
 
 export const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB
 export const MAX_LOG_LINES = 1000;
@@ -67,6 +70,12 @@ export const clearLogsIfLocalStorageLimitExceeded = () => {
     }
 };
 
+export const logStartupMessage = async () => {
+    addLogLine(`User ID: ${(getData(LS_KEYS.USER) as User)?.id}`);
+    addLogLine(`Sentry ID: ${await getSentryUserID()}`);
+    addLogLine(`Git commit: ${process.env.GIT_SHA}`);
+};
+
 function getLogs(): Log[] {
     return getData(LS_KEYS.LOGS)?.logs ?? [];
 }

+ 1 - 3
packages/shared/network/api.ts

@@ -85,6 +85,4 @@ export const getFamilyPortalURL = () => {
  *   assigns development when running the `next dev` command, or production for
  *   all other commands.
  */
-export const isDevBuild = () => {
-    return process.env.NODE_ENV === 'development';
-};
+export const isDevBuild = process.env.NODE_ENV === 'development';

+ 16 - 0
packages/shared/next/next.config.base.js

@@ -1,3 +1,13 @@
+/**
+ * @file Configure the Next.js build
+ *
+ * This file gets used by the Next.js build phase, and is not included in the
+ * browser build. It will not be parsed by Webpack, Babel or TypeScript, so
+ * don't use features that will not be available in our target node version.
+ *
+ * https://nextjs.org/docs/pages/api-reference/next-config-js
+ */
+
 const { withSentryConfig } = require('@sentry/nextjs');
 const cp = require('child_process');
 
@@ -27,6 +37,12 @@ const nextConfig = {
     },
     transpilePackages: ['@mui/material', '@mui/system', '@mui/icons-material'],
 
+    // Add environment variables to the JavaScript bundle. They will be
+    // available as `process.env.VAR_NAME` to our code.
+    env: {
+        GIT_SHA: gitSHA,
+    },
+
     // https://dev.to/marcinwosinek/how-to-add-resolve-fallback-to-webpack-5-in-nextjs-10-i6j
     webpack: (config, { isServer }) => {
         if (!isServer) {

+ 1 - 2
turbo.json

@@ -25,7 +25,6 @@
         "NEXT_PUBLIC_ENTE_ALBUM_ENDPOINT",
         "NEXT_PUBLIC_ENTE_FAMILY_PORTAL_ENDPOINT",
         "NODE_ENV",
-        "SENTRY_AUTH_TOKEN",
-        "SENTRY_RELEASE"
+        "SENTRY_AUTH_TOKEN"
     ]
 }