feat: add random identifier to bugsnag reports

This commit is contained in:
Baptiste Grob
2021-01-22 15:31:56 +01:00
parent 2c4742a91d
commit 0bd3143481
6 changed files with 49 additions and 8 deletions

View File

@@ -2,6 +2,7 @@ import { isNullOrUndefined, SNLog } from '@standardnotes/snjs';
import { isDesktopApplication, isDev } from '@/utils';
import { storage, StorageKey } from './localStorage';
import Bugsnag from '@bugsnag/js';
import { WebCrypto } from '../crypto';
declare const __VERSION__: string;
declare global {
@@ -21,7 +22,7 @@ function redactFilePath(line: string): string {
}
}
export function startErrorReporting() {
export function startErrorReporting(): void {
const disableErrorReporting = storage.get(StorageKey.DisableErrorReporting);
if (
/**
@@ -37,6 +38,15 @@ export function startErrorReporting() {
return;
}
try {
const storedUserId = storage.get(StorageKey.AnonymousUserId);
let anonymousUserId: string;
if (storedUserId === null) {
anonymousUserId = WebCrypto.generateUUIDSync();
storage.set(StorageKey.AnonymousUserId, anonymousUserId);
} else {
anonymousUserId = storedUserId;
}
Bugsnag.start({
apiKey: window._bugsnag_api_key,
appType: isDesktopApplication() ? 'desktop' : 'web',
@@ -46,6 +56,8 @@ export function startErrorReporting() {
releaseStage: isDev ? 'development' : undefined,
enabledBreadcrumbTypes: ['error', 'log'],
onError(event) {
event.setUser(anonymousUserId);
/**
* Redact any data that could be used to identify user,
* such as file paths.
@@ -95,3 +107,16 @@ export function startErrorReporting() {
SNLog.onError = console.error;
}
}
export function disableErrorReporting() {
storage.remove(StorageKey.AnonymousUserId);
storage.set(StorageKey.DisableErrorReporting, true);
}
export function enableErrorReporting() {
storage.set(StorageKey.DisableErrorReporting, false);
}
export function errorReportingId() {
return storage.get(StorageKey.AnonymousUserId);
}