1
1
import * as Sentry from '@sentry/browser' ;
2
+ import * as uuid from 'uuid/v4' ;
2
3
3
4
import { UI_VERSION , serverVersion , desktopVersion } from './services/service-versions' ;
4
5
import { ApiError } from './services/server-api-types' ;
@@ -12,49 +13,63 @@ export function isSentryInitialized() {
12
13
export { Sentry } ;
13
14
14
15
export function initSentry ( dsn : string | undefined ) {
15
- if ( dsn ) {
16
- Sentry . init ( {
17
- dsn : dsn ,
18
- release : UI_VERSION ,
19
- ignoreErrors : [
20
- 'ResizeObserver loop limit exceeded' , // No visible effect: https://stackoverflow.com/a/50387233/68051
21
- ] ,
22
- beforeSend : function ( event , hint ) {
23
- const exception = hint ?. originalException ;
24
- if ( exception instanceof ApiError ) {
25
- event . fingerprint = [
26
- "{{ default }}" ,
27
- exception . operationName ,
28
- ...( exception . errorCode
29
- ? [ exception . errorCode . toString ( ) ]
30
- : [ ]
31
- )
32
- ] ;
33
- }
34
- return event ;
16
+ if ( ! dsn ) return ;
17
+
18
+ Sentry . init ( {
19
+ dsn : dsn ,
20
+ release : UI_VERSION ,
21
+ ignoreErrors : [
22
+ 'ResizeObserver loop limit exceeded' , // No visible effect: https://stackoverflow.com/a/50387233/68051
23
+ ] ,
24
+ beforeSend : function ( event , hint ) {
25
+ const exception = hint ?. originalException ;
26
+ if ( exception instanceof ApiError ) {
27
+ event . fingerprint = [
28
+ "{{ default }}" ,
29
+ exception . operationName ,
30
+ ...( exception . errorCode
31
+ ? [ exception . errorCode . toString ( ) ]
32
+ : [ ]
33
+ )
34
+ ] ;
35
35
}
36
- } ) ;
37
- sentryInitialized = true ;
38
-
39
- serverVersion . then ( ( version ) => addErrorTag ( 'version:server' , version ) ) ;
40
- desktopVersion . then ( ( version ) => addErrorTag ( 'version:desktop' , version ) ) ;
41
-
42
- // If we're running in the main window (not the SW),
43
- // stop reporting errors after the page starts unloading
44
- if ( typeof window !== 'undefined' ) {
45
- window . addEventListener ( 'beforeunload' , ( ) => {
46
- Sentry . getCurrentHub ( ) . getClient ( ) . getOptions ( ) . enabled = false ;
47
- sentryInitialized = false ;
48
- } ) ;
36
+ return event ;
49
37
}
38
+ } ) ;
39
+ sentryInitialized = true ;
40
+
41
+ serverVersion . then ( ( version ) => addErrorTag ( 'version:server' , version ) ) ;
42
+ desktopVersion . then ( ( version ) => addErrorTag ( 'version:desktop' , version ) ) ;
43
+
44
+ // If we're running in the main window (not the SW),
45
+ // stop reporting errors after the page starts unloading
46
+ if ( typeof window !== 'undefined' ) {
47
+ window . addEventListener ( 'beforeunload' , ( ) => {
48
+ Sentry . getCurrentHub ( ) . getClient ( ) . getOptions ( ) . enabled = false ;
49
+ sentryInitialized = false ;
50
+ } ) ;
50
51
}
52
+
53
+ Sentry . configureScope ( ( scope ) => {
54
+ // We use a random id to distinguish between many errors in one session vs
55
+ // one error in many sessions. This isn't persisted and can't be used to
56
+ // identify anybody between sessions.
57
+ const randomId = uuid ( ) ;
58
+ scope . setUser ( {
59
+ id : randomId ,
60
+ username : `anon-${ randomId } `
61
+ } ) ;
62
+ } ) ;
51
63
}
52
64
53
65
export function logErrorsAsUser ( email : string | undefined ) {
54
66
if ( ! sentryInitialized ) return ;
55
67
56
68
Sentry . configureScope ( ( scope ) => {
57
- scope . setUser ( { email : email } ) ;
69
+ scope . setUser ( {
70
+ id : email ,
71
+ email : email
72
+ } ) ;
58
73
} ) ;
59
74
}
60
75
0 commit comments