@@ -16,6 +16,9 @@ const HISTORY = 'history';
16
16
const DOM = 'dom' ;
17
17
const XHR = 'xhr' ;
18
18
19
+ type AddBreadcrumb = Hub [ 'addBreadcrumb' ] ;
20
+ type AddBreadcrumbParams = Parameters < AddBreadcrumb > ;
21
+
19
22
/** JSDoc */
20
23
interface BreadcrumbsOptions {
21
24
console : boolean ;
@@ -71,9 +74,17 @@ export class Breadcrumbs implements Integration {
71
74
public setupOnce ( addGlobalEventProcessor : ( callback : EventProcessor ) => void , getCurrentHub : ( ) => Hub ) : void {
72
75
const hub = getCurrentHub ( ) ;
73
76
77
+ // Alias the addBreadcrumb function to save on bundle size
78
+ function addBreadcrumb (
79
+ breadcrumb : AddBreadcrumbParams [ 0 ] ,
80
+ breadcrumbHint : AddBreadcrumbParams [ 1 ] ,
81
+ ) : ReturnType < AddBreadcrumb > {
82
+ hub . addBreadcrumb ( breadcrumb , breadcrumbHint ) ;
83
+ }
84
+
74
85
addGlobalEventProcessor ( event => {
75
86
if ( this . _options . sentry ) {
76
- hub . addBreadcrumb (
87
+ addBreadcrumb (
77
88
{
78
89
category : `sentry.${ event . type === 'transaction' ? 'transaction' : 'event' } ` ,
79
90
event_id : event . event_id ,
@@ -89,27 +100,27 @@ export class Breadcrumbs implements Integration {
89
100
} ) ;
90
101
91
102
if ( this . _options . console ) {
92
- _addConsoleBreadcrumbs ( hub ) ;
103
+ _addConsoleBreadcrumbs ( addBreadcrumb ) ;
93
104
}
94
105
if ( this . _options . dom ) {
95
- _addDomBreadcrumbs ( hub , this . _options . dom ) ;
106
+ _addDomBreadcrumbs ( addBreadcrumb , this . _options . dom ) ;
96
107
}
97
108
if ( this . _options . xhr ) {
98
- _addXhrBreadcrumbs ( hub ) ;
109
+ _addXhrBreadcrumbs ( addBreadcrumb ) ;
99
110
}
100
111
if ( this . _options . fetch ) {
101
- _addFetchBreadcrumbs ( hub ) ;
112
+ _addFetchBreadcrumbs ( addBreadcrumb ) ;
102
113
}
103
114
if ( this . _options . history ) {
104
- _addHistoryBreadcrumbs ( hub ) ;
115
+ _addHistoryBreadcrumbs ( addBreadcrumb ) ;
105
116
}
106
117
}
107
118
}
108
119
109
120
/**
110
121
* Creates breadcrumbs from console API calls
111
122
*/
112
- function _addConsoleBreadcrumbs ( hub : Hub ) : void {
123
+ function _addConsoleBreadcrumbs ( addBreadcrumb : AddBreadcrumb ) : void {
113
124
// eslint-disable-next-line @typescript-eslint/no-explicit-any
114
125
addInstrumentationHandler ( ( handlerData : { [ key : string ] : any } ) : void => {
115
126
const breadcrumb = {
@@ -132,7 +143,7 @@ function _addConsoleBreadcrumbs(hub: Hub): void {
132
143
}
133
144
}
134
145
135
- hub . addBreadcrumb ( breadcrumb , {
146
+ addBreadcrumb ( breadcrumb , {
136
147
input : handlerData . args ,
137
148
level : handlerData . level ,
138
149
} ) ;
@@ -142,47 +153,46 @@ function _addConsoleBreadcrumbs(hub: Hub): void {
142
153
/**
143
154
* Creates breadcrumbs from DOM API calls
144
155
*/
145
- function _addDomBreadcrumbs ( hub : Hub , dom : BreadcrumbsOptions [ 'dom' ] ) : void {
156
+ function _addDomBreadcrumbs ( addBreadcrumb : AddBreadcrumb , dom : BreadcrumbsOptions [ 'dom' ] ) : void {
146
157
// eslint-disable-next-line @typescript-eslint/no-explicit-any
147
158
addInstrumentationHandler ( ( handlerData : { [ key : string ] : any } ) : void => {
148
- let target ;
159
+ const { event , name , global } = handlerData ;
149
160
let keyAttrs = typeof dom === 'object' ? dom . serializeAttribute : undefined ;
150
161
151
162
if ( typeof keyAttrs === 'string' ) {
152
163
keyAttrs = [ keyAttrs ] ;
153
164
}
154
165
155
166
// Accessing event.target can throw (see getsentry/raven-js#838, #768)
167
+ let target ;
156
168
try {
157
- target = handlerData . event . target
158
- ? htmlTreeAsString ( handlerData . event . target as Node , keyAttrs )
159
- : htmlTreeAsString ( ( handlerData . event as unknown ) as Node , keyAttrs ) ;
169
+ target = event . target
170
+ ? htmlTreeAsString ( event . target as Node , keyAttrs )
171
+ : htmlTreeAsString ( ( event as unknown ) as Node , keyAttrs ) ;
160
172
} catch ( e ) {
161
173
target = '<unknown>' ;
162
174
}
163
175
164
- if ( target . length === 0 ) {
165
- return ;
176
+ if ( target ) {
177
+ addBreadcrumb (
178
+ {
179
+ category : `ui.${ name } ` ,
180
+ message : target ,
181
+ } ,
182
+ {
183
+ event,
184
+ name,
185
+ global,
186
+ } ,
187
+ ) ;
166
188
}
167
-
168
- hub . addBreadcrumb (
169
- {
170
- category : `ui.${ handlerData . name } ` ,
171
- message : target ,
172
- } ,
173
- {
174
- event : handlerData . event ,
175
- name : handlerData . name ,
176
- global : handlerData . global ,
177
- } ,
178
- ) ;
179
189
} , DOM ) ;
180
190
}
181
191
182
192
/**
183
193
* Creates breadcrumbs from XHR API calls
184
194
*/
185
- function _addXhrBreadcrumbs ( hub : Hub ) : void {
195
+ function _addXhrBreadcrumbs ( addBreadcrumb : AddBreadcrumb ) : void {
186
196
// eslint-disable-next-line @typescript-eslint/no-explicit-any
187
197
addInstrumentationHandler ( ( handlerData : { [ key : string ] : any } ) : void => {
188
198
if ( handlerData . endTimestamp ) {
@@ -193,7 +203,7 @@ function _addXhrBreadcrumbs(hub: Hub): void {
193
203
194
204
const { method, url, status_code, body } = handlerData . xhr . __sentry_xhr__ || { } ;
195
205
196
- hub . addBreadcrumb (
206
+ addBreadcrumb (
197
207
{
198
208
category : XHR ,
199
209
data : {
@@ -215,7 +225,7 @@ function _addXhrBreadcrumbs(hub: Hub): void {
215
225
/**
216
226
* Creates breadcrumbs from fetch API calls
217
227
*/
218
- function _addFetchBreadcrumbs ( hub : Hub ) : void {
228
+ function _addFetchBreadcrumbs ( addBreadcrumb : AddBreadcrumb ) : void {
219
229
// eslint-disable-next-line @typescript-eslint/no-explicit-any
220
230
addInstrumentationHandler ( ( handlerData : { [ key : string ] : any } ) : void => {
221
231
// We only capture complete fetch requests
@@ -239,19 +249,19 @@ function _addFetchBreadcrumbs(hub: Hub): void {
239
249
240
250
if ( handlerData . error ) {
241
251
breadcrumbHint . data = handlerData . error ;
242
- hub . addBreadcrumb ( breadcrumb , breadcrumbHint ) ;
252
+ addBreadcrumb ( breadcrumb , breadcrumbHint ) ;
243
253
} else {
244
254
breadcrumb . data . status_code = handlerData . response . status ;
245
255
breadcrumbHint . response = handlerData . response ;
246
- hub . addBreadcrumb ( breadcrumb , breadcrumbHint ) ;
256
+ addBreadcrumb ( breadcrumb , breadcrumbHint ) ;
247
257
}
248
258
} , FETCH ) ;
249
259
}
250
260
251
261
/**
252
262
* Creates breadcrumbs from history API calls
253
263
*/
254
- function _addHistoryBreadcrumbs ( hub : Hub ) : void {
264
+ function _addHistoryBreadcrumbs ( addBreadcrumb : AddBreadcrumb ) : void {
255
265
// eslint-disable-next-line @typescript-eslint/no-explicit-any
256
266
addInstrumentationHandler ( ( handlerData : { [ key : string ] : any } ) : void => {
257
267
let { from, to } = handlerData ;
@@ -274,7 +284,7 @@ function _addHistoryBreadcrumbs(hub: Hub): void {
274
284
from = parsedFrom . relative ;
275
285
}
276
286
277
- hub . addBreadcrumb ( {
287
+ addBreadcrumb ( {
278
288
category : 'navigation' ,
279
289
data : {
280
290
from,
0 commit comments