make sentry userID anonymized

This commit is contained in:
Abhinav-grd 2021-08-04 12:34:49 +05:30
parent 5ce89b27ef
commit 39d8de6c6e
5 changed files with 30 additions and 7 deletions

View file

@ -1,13 +1,12 @@
import * as Sentry from '@sentry/nextjs';
import { getSentryTunnelUrl } from 'utils/common/apiUtil';
import { getData, LS_KEYS } from 'utils/storage/localStorage';
import { getUserAnonymizedID } from 'utils/user';
const SENTRY_DSN = process.env.NEXT_PUBLIC_SENTRY_DSN ?? 'https://860186db60c54c7fbacfe255124958e8@errors.ente.io/4';
const SENTRY_ENV = process.env.NEXT_PUBLIC_SENTRY_ENV ?? 'development';
const userID = getData(LS_KEYS.USER)?.id;
Sentry.setUser({ id: userID });
Sentry.setUser({ id: getUserAnonymizedID() });
Sentry.init({
dsn: SENTRY_DSN,
enabled: SENTRY_ENV !== 'development',

View file

@ -11,6 +11,7 @@ import SignUp from 'components/SignUp';
import constants from 'utils/strings/constants';
import localForage from 'utils/storage/localForage';
import IncognitoWarning from 'components/IncognitoWarning';
import { logError } from 'utils/sentry';
const Container = styled.div`
display: flex;
@ -110,6 +111,7 @@ export default function LandingPage() {
try {
await localForage.ready();
} catch (e) {
logError(e, 'usage in incognito mode tried');
setBlockUsage(true);
}
setLoading(false);

View file

@ -1,11 +1,11 @@
import * as Sentry from '@sentry/nextjs';
import { getData, LS_KEYS } from 'utils/storage/localStorage';
import { getUserAnonymizedID } from 'utils/user';
export const logError = (e: any, msg?: string) => {
const userID = getData(LS_KEYS.USER)?.id;
Sentry.captureException(e, {
level: Sentry.Severity.Info,
user: { id: userID },
user: { id: getUserAnonymizedID() },
contexts: {
context: {
message: msg,

View file

@ -10,7 +10,8 @@ export enum LS_KEYS {
IS_FIRST_LOGIN = 'isFirstLogin',
JUST_SIGNED_UP = 'justSignedUp',
SHOW_BACK_BUTTON = 'showBackButton',
EXPORT = 'export'
EXPORT = 'export',
AnonymizeUserID='anonymizedUserID'
}
export const setData = (key: LS_KEYS, value: object) => {

21
src/utils/user/index.ts Normal file
View file

@ -0,0 +1,21 @@
import { getData, LS_KEYS, setData } from 'utils/storage/localStorage';
export function makeID(length) {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
for ( let i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
}
return result;
}
export function getUserAnonymizedID() {
let anonymizeUserID = getData(LS_KEYS.AnonymizeUserID)?.id;
if (!anonymizeUserID) {
anonymizeUserID=makeID(6);
setData(LS_KEYS.AnonymizeUserID, { id: anonymizeUserID });
}
return anonymizeUserID;
}