Merge pull request #766 from ente-io/fix-sentry-id-logging-on-desktop

Fix sentry id logging on desktop
This commit is contained in:
Abhinav Kumar 2022-11-08 13:07:39 +05:30 committed by GitHub
commit f16cee2149
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 19 deletions

View file

@ -41,7 +41,6 @@ module.exports = (phase) =>
},
env: {
SENTRY_RELEASE: GIT_SHA,
NEXT_PUBLIC_LATEST_COMMIT_HASH: GIT_SHA,
},
workbox: WORKBOX_CONFIG,

View file

@ -4,9 +4,6 @@ import { downloadAsFile } from 'utils/file';
import constants from 'utils/strings/constants';
import { addLogLine, getDebugLogs } from 'utils/logging';
import SidebarButton from './Button';
import { getData, LS_KEYS } from 'utils/storage/localStorage';
import { User } from 'types/user';
import { getSentryUserID } from 'utils/user';
import isElectron from 'is-electron';
import ElectronService from 'services/electron/common';
@ -27,11 +24,6 @@ export default function DebugLogs() {
});
const downloadDebugLogs = () => {
addLogLine(
'latest commit id :' + process.env.NEXT_PUBLIC_LATEST_COMMIT_HASH
);
addLogLine(`user sentry id ${getSentryUserID()}`);
addLogLine(`ente userID ${(getData(LS_KEYS.USER) as User)?.id}`);
addLogLine('exporting logs');
if (isElectron()) {
ElectronService.openLogDirectory();

View file

@ -26,7 +26,10 @@ import {
getRoadmapRedirectURL,
} from 'services/userService';
import { CustomError } from 'utils/error';
import { clearLogsIfLocalStorageLimitExceeded } from 'utils/logging';
import {
addLogLine,
clearLogsIfLocalStorageLimitExceeded,
} from 'utils/logging';
import isElectron from 'is-electron';
import ElectronUpdateService from 'services/electron/update';
import {
@ -40,6 +43,8 @@ import {
} from 'types/Notification';
import ArrowForward from '@mui/icons-material/ArrowForward';
import { AppUpdateInfo } from 'types/electron';
import { getSentryUserID } from 'utils/user';
import { User } from 'types/user';
export const MessageContainer = styled('div')`
background-color: #111;
@ -153,6 +158,12 @@ export default function App({ Component, err }) {
}
);
clearLogsIfLocalStorageLimitExceeded();
const main = async () => {
addLogLine(`userID: ${(getData(LS_KEYS.USER) as User)?.id}`);
addLogLine(`sentryID: ${await getSentryUserID()}`);
addLogLine(`sentry release ID: ${process.env.SENTRY_RELEASE}`);
};
main();
}, []);
useEffect(() => {

View file

@ -23,6 +23,12 @@ class ElectronService {
this.electronAPIs.openLogDirectory();
}
}
getSentryUserID() {
if (this.electronAPIs?.getSentryUserID) {
return this.electronAPIs.getSentryUserID();
}
}
}
export default new ElectronService();

View file

@ -75,4 +75,5 @@ export interface ElectronAPIs {
) => void;
updateAndRestart: () => void;
skipAppVersion: (version: string) => void;
getSentryUserID: () => Promise<string>;
}

View file

@ -69,7 +69,6 @@ export const clearLogsIfLocalStorageLimitExceeded = () => {
addLogLine(`app started`);
} catch (e) {
deleteLogs();
logError(e, 'failed to log test log');
}
}
addLogLine(`logs size: ${convertBytesToHumanReadable(logSize)}`);

View file

@ -3,7 +3,7 @@ import { isDEVSentryENV } from 'constants/sentry';
import { addLogLine } from 'utils/logging';
import { getSentryUserID } from 'utils/user';
export const logError = (
export const logError = async (
error: any,
msg: string,
info?: Record<string, unknown>,
@ -25,7 +25,7 @@ export const logError = (
}
Sentry.captureException(err, {
level: Sentry.Severity.Info,
user: { id: getSentryUserID() },
user: { id: await getSentryUserID() },
contexts: {
...(info && {
info: info,

View file

@ -1,5 +1,7 @@
import isElectron from 'is-electron';
import { UserDetails } from 'types/user';
import { getData, LS_KEYS, setData } from 'utils/storage/localStorage';
import ElectronService from 'services/electron/common';
export function makeID(length) {
let result = '';
@ -14,13 +16,17 @@ export function makeID(length) {
return result;
}
export function getSentryUserID() {
let anonymizeUserID = getData(LS_KEYS.AnonymizedUserID)?.id;
if (!anonymizeUserID) {
anonymizeUserID = makeID(6);
setData(LS_KEYS.AnonymizedUserID, { id: anonymizeUserID });
export async function getSentryUserID() {
if (isElectron()) {
return await ElectronService.getSentryUserID();
} else {
let anonymizeUserID = getData(LS_KEYS.AnonymizedUserID)?.id;
if (!anonymizeUserID) {
anonymizeUserID = makeID(6);
setData(LS_KEYS.AnonymizedUserID, { id: anonymizeUserID });
}
return anonymizeUserID;
}
return anonymizeUserID;
}
export function getLocalUserDetails(): UserDetails {