1
1
// Very happy integration that'll prepend and append very happy stick figure to the message
2
2
class HappyIntegration {
3
3
constructor ( ) {
4
- this . name = " HappyIntegration" ;
4
+ this . name = ' HappyIntegration' ;
5
5
}
6
6
7
7
setupOnce ( ) {
8
- Sentry . addGlobalEventProcessor ( async ( event ) => {
8
+ Sentry . addGlobalEventProcessor ( async event => {
9
9
const self = getCurrentHub ( ) . getIntegration ( HappyIntegration ) ;
10
10
// Run the integration ONLY when it was installed on the current Hub
11
11
if ( self ) {
12
- if ( event . message === " Happy Message" ) {
12
+ if ( event . message === ' Happy Message' ) {
13
13
event . message = `\\o/ ${ event . message } \\o/` ;
14
14
}
15
15
}
@@ -20,23 +20,26 @@ class HappyIntegration {
20
20
21
21
class HappyTransport extends Sentry . Transports . BaseTransport {
22
22
captureEvent ( event ) {
23
- console . log ( `This is the place where you'd implement your own sending logic. It'd get url: ${ this . url } and an event itself:` , event ) ;
23
+ console . log (
24
+ `This is the place where you'd implement your own sending logic. It'd get url: ${ this . url } and an event itself:` ,
25
+ event ,
26
+ ) ;
24
27
25
28
return {
26
- status : 'success'
27
- }
29
+ status : 'success' ,
30
+ } ;
28
31
}
29
32
}
30
33
31
34
Sentry . init ( {
32
35
// Client's DSN.
33
- dsn :
" https://[email protected] /297378" ,
36
+ dsn :
' https://[email protected] /297378' ,
34
37
// An array of strings or regexps that'll be used to ignore specific errors based on their type/message
35
- ignoreErrors : [ / P i c k l e R i c k _ \d \d / , " RangeError" ] ,
38
+ ignoreErrors : [ / P i c k l e R i c k _ \d \d / , ' RangeError' ] ,
36
39
// // An array of strings or regexps that'll be used to ignore specific errors based on their origin url
37
- blacklistUrls : [ " external-lib.js" ] ,
40
+ blacklistUrls : [ ' external-lib.js' ] ,
38
41
// // An array of strings or regexps that'll be used to allow specific errors based on their origin url
39
- whitelistUrls : [ " http://localhost:5000" , " https://browser.sentry-cdn" ] ,
42
+ whitelistUrls : [ ' http://localhost:5000' , ' https://browser.sentry-cdn' ] ,
40
43
// // Debug mode with valuable initialization/lifecycle informations.
41
44
debug : true ,
42
45
// Whether SDK should be enabled or not.
@@ -46,9 +49,9 @@ Sentry.init({
46
49
return [ new HappyIntegration ( ) , ...integrations ] ;
47
50
} ,
48
51
// A release identifier.
49
- release : " 1537345109360" ,
52
+ release : ' 1537345109360' ,
50
53
// An environment identifier.
51
- environment : " staging" ,
54
+ environment : ' staging' ,
52
55
// Custom event transport that will be used to send things to Sentry
53
56
transport : HappyTransport ,
54
57
// Method called for every captured event
@@ -58,11 +61,11 @@ Sentry.init({
58
61
// Our CustomError defined in errors.js has `someMethodAttachedToOurCustomError`
59
62
// which can mimick something like a network request to grab more detailed error info or something.
60
63
// hint is original exception that was triggered, so we check for our CustomError name
61
- if ( hint . originalException . name === " CustomError" ) {
64
+ if ( hint . originalException . name === ' CustomError' ) {
62
65
const serverData = await hint . originalException . someMethodAttachedToOurCustomError ( ) ;
63
66
event . extra = {
64
67
...event . extra ,
65
- serverData
68
+ serverData,
66
69
} ;
67
70
}
68
71
console . log ( event ) ;
@@ -71,88 +74,88 @@ Sentry.init({
71
74
// Method called for every captured breadcrumb
72
75
beforeBreadcrumb ( breadcrumb , hint ) {
73
76
// We ignore our own logger and rest of the buttons just for presentation purposes
74
- if ( breadcrumb . message . startsWith ( " Sentry Logger" ) ) return null ;
75
- if ( breadcrumb . category !== " ui.click" || hint . event . target . id !== " breadcrumb-hint" ) return null ;
77
+ if ( breadcrumb . message . startsWith ( ' Sentry Logger' ) ) return null ;
78
+ if ( breadcrumb . category !== ' ui.click' || hint . event . target . id !== ' breadcrumb-hint' ) return null ;
76
79
77
80
// If we have a `ui.click` type of breadcrumb, eg. clicking on a button we defined in index.html
78
81
// We will extract a `data-label` attribute from it and use it as a part of the message
79
- if ( breadcrumb . category === " ui.click" ) {
82
+ if ( breadcrumb . category === ' ui.click' ) {
80
83
const label = hint . event . target . dataset . label ;
81
84
if ( label ) {
82
85
breadcrumb . message = `User clicked on a button with label "${ label } "` ;
83
86
}
84
87
}
85
88
console . log ( breadcrumb ) ;
86
89
return breadcrumb ;
87
- }
90
+ } ,
88
91
} ) ;
89
92
90
93
// Testing code, irrelevant vvvvv
91
94
92
- document . addEventListener ( " DOMContentLoaded" , ( ) => {
93
- document . querySelector ( " #blacklist-url" ) . addEventListener ( " click" , ( ) => {
94
- const script = document . createElement ( " script" ) ;
95
- script . crossOrigin = " anonymous" ;
95
+ document . addEventListener ( ' DOMContentLoaded' , ( ) => {
96
+ document . querySelector ( ' #blacklist-url' ) . addEventListener ( ' click' , ( ) => {
97
+ const script = document . createElement ( ' script' ) ;
98
+ script . crossOrigin = ' anonymous' ;
96
99
script . src =
97
- " https://rawgit.com/kamilogorek/cfbe9f92196c6c61053b28b2d42e2f5d/raw/3aef6ff5e2fd2ad4a84205cd71e2496a445ebe1d/external-lib.js" ;
100
+ ' https://rawgit.com/kamilogorek/cfbe9f92196c6c61053b28b2d42e2f5d/raw/3aef6ff5e2fd2ad4a84205cd71e2496a445ebe1d/external-lib.js' ;
98
101
document . body . appendChild ( script ) ;
99
102
} ) ;
100
103
101
- document . querySelector ( " #whitelist-url" ) . addEventListener ( " click" , ( ) => {
102
- const script = document . createElement ( " script" ) ;
103
- script . crossOrigin = " anonymous" ;
104
+ document . querySelector ( ' #whitelist-url' ) . addEventListener ( ' click' , ( ) => {
105
+ const script = document . createElement ( ' script' ) ;
106
+ script . crossOrigin = ' anonymous' ;
104
107
script . src =
105
- " https://rawgit.com/kamilogorek/cb67dafbd0e12b782bdcc1fbcaed2b87/raw/3aef6ff5e2fd2ad4a84205cd71e2496a445ebe1d/lib.js" ;
108
+ ' https://rawgit.com/kamilogorek/cb67dafbd0e12b782bdcc1fbcaed2b87/raw/3aef6ff5e2fd2ad4a84205cd71e2496a445ebe1d/lib.js' ;
106
109
document . body . appendChild ( script ) ;
107
110
} ) ;
108
111
109
- document . querySelector ( " #ignore-message" ) . addEventListener ( " click" , ( ) => {
110
- throw new Error ( " Exception that will be ignored because of this keyword => PickleRick_42 <=" ) ;
112
+ document . querySelector ( ' #ignore-message' ) . addEventListener ( ' click' , ( ) => {
113
+ throw new Error ( ' Exception that will be ignored because of this keyword => PickleRick_42 <=' ) ;
111
114
} ) ;
112
115
113
- document . querySelector ( " #ignore-type" ) . addEventListener ( " click" , ( ) => {
116
+ document . querySelector ( ' #ignore-type' ) . addEventListener ( ' click' , ( ) => {
114
117
throw new RangeError ( "Exception that will be ignored because of it's type" ) ;
115
118
} ) ;
116
119
117
- document . querySelector ( " #regular-exception" ) . addEventListener ( " click" , ( ) => {
120
+ document . querySelector ( ' #regular-exception' ) . addEventListener ( ' click' , ( ) => {
118
121
throw new Error ( `Regular exception no. ${ Date . now ( ) } ` ) ;
119
122
} ) ;
120
123
121
- document . querySelector ( " #capture-exception" ) . addEventListener ( " click" , ( ) => {
124
+ document . querySelector ( ' #capture-exception' ) . addEventListener ( ' click' , ( ) => {
122
125
Sentry . captureException ( new Error ( `captureException call no. ${ Date . now ( ) } ` ) ) ;
123
126
} ) ;
124
127
125
- document . querySelector ( " #capture-message" ) . addEventListener ( " click" , ( ) => {
128
+ document . querySelector ( ' #capture-message' ) . addEventListener ( ' click' , ( ) => {
126
129
Sentry . captureMessage ( `captureMessage call no. ${ Date . now ( ) } ` ) ;
127
130
} ) ;
128
131
129
- document . querySelector ( " #duplicate-exception" ) . addEventListener ( " click" , ( ) => {
130
- Sentry . captureException ( new Error ( " duplicated exception" ) ) ;
132
+ document . querySelector ( ' #duplicate-exception' ) . addEventListener ( ' click' , ( ) => {
133
+ Sentry . captureException ( new Error ( ' duplicated exception' ) ) ;
131
134
} ) ;
132
135
133
- document . querySelector ( " #duplicate-message" ) . addEventListener ( " click" , ( ) => {
134
- Sentry . captureMessage ( " duplicate captureMessage" ) ;
136
+ document . querySelector ( ' #duplicate-message' ) . addEventListener ( ' click' , ( ) => {
137
+ Sentry . captureMessage ( ' duplicate captureMessage' ) ;
135
138
} ) ;
136
139
137
- document . querySelector ( " #integration-example" ) . addEventListener ( " click" , ( ) => {
138
- Sentry . captureMessage ( " Happy Message" ) ;
140
+ document . querySelector ( ' #integration-example' ) . addEventListener ( ' click' , ( ) => {
141
+ Sentry . captureMessage ( ' Happy Message' ) ;
139
142
} ) ;
140
143
141
- document . querySelector ( " #exception-hint" ) . addEventListener ( " click" , ( ) => {
144
+ document . querySelector ( ' #exception-hint' ) . addEventListener ( ' click' , ( ) => {
142
145
class CustomError extends Error {
143
146
constructor ( ...args ) {
144
147
super ( ...args ) ;
145
- this . name = " CustomError" ;
148
+ this . name = ' CustomError' ;
146
149
}
147
150
someMethodAttachedToOurCustomError ( ) {
148
151
return new Promise ( resolve => {
149
- resolve ( " some data, who knows what exactly" ) ;
152
+ resolve ( ' some data, who knows what exactly' ) ;
150
153
} ) ;
151
154
}
152
155
}
153
156
154
- throw new CustomError ( " Hey there" ) ;
157
+ throw new CustomError ( ' Hey there' ) ;
155
158
} ) ;
156
159
157
- document . querySelector ( " #breadcrumb-hint" ) . addEventListener ( " click" , ( ) => { } ) ;
160
+ document . querySelector ( ' #breadcrumb-hint' ) . addEventListener ( ' click' , ( ) => { } ) ;
158
161
} ) ;
0 commit comments