@@ -6,6 +6,13 @@ interface TracingOptions {
6
6
tracingOrigins : Array < string | RegExp > ;
7
7
traceFetch : boolean ;
8
8
traceXHR : boolean ;
9
+ /**
10
+ * This function will be called before creating a span for a request with the given url.
11
+ * Return false if you don't want a span for the given url.
12
+ *
13
+ * By default it uses the `tracingOrigins` options as a url match.
14
+ */
15
+ shouldCreateSpanForRequest ( url : string ) : boolean ;
9
16
idleTimeout : number ;
10
17
startTransactionOnLocationChange : boolean ;
11
18
tracesSampleRate : number ;
@@ -70,6 +77,10 @@ export class Tracing implements Integration {
70
77
const defaultTracingOrigins = [ 'localhost' , / ^ \/ / ] ;
71
78
const defaults = {
72
79
idleTimeout : 500 ,
80
+ shouldCreateSpanForRequest ( url : string ) : boolean {
81
+ const origins = ( _options && _options . tracingOrigins ) || defaultTracingOrigins ;
82
+ return origins . some ( ( origin : string | RegExp ) => isMatchingPattern ( url , origin ) ) ;
83
+ } ,
73
84
startTransactionOnLocationChange : true ,
74
85
traceFetch : true ,
75
86
traceXHR : true ,
@@ -393,17 +404,32 @@ export class Tracing implements Integration {
393
404
* Creates breadcrumbs from XHR API calls
394
405
*/
395
406
function xhrCallback ( handlerData : { [ key : string ] : any } ) : void {
407
+ if ( ! Tracing . options . traceXHR ) {
408
+ return ;
409
+ }
410
+
411
+ // tslint:disable-next-line: no-unsafe-any
412
+ if ( ! handlerData || ! handlerData . xhr || ! handlerData . xhr . __sentry_xhr__ ) {
413
+ return ;
414
+ }
415
+
396
416
// tslint:disable: no-unsafe-any
397
- if ( handlerData . requestComplete && handlerData . xhr . __sentry_xhr_activity_id__ ) {
398
- Tracing . popActivity ( handlerData . xhr . __sentry_xhr_activity_id__ , handlerData . xhr . __sentry_xhr__ ) ;
417
+ const xhr = handlerData . xhr . __sentry_xhr__ ;
418
+
419
+ if ( ! Tracing . options . shouldCreateSpanForRequest ( xhr . url ) ) {
399
420
return ;
400
421
}
422
+
401
423
// We only capture complete, non-sentry requests
402
424
if ( handlerData . xhr . __sentry_own_request__ ) {
403
425
return ;
404
426
}
405
427
406
- const xhr = handlerData . xhr . __sentry_xhr__ ;
428
+ if ( handlerData . requestComplete && handlerData . xhr . __sentry_xhr_activity_id__ ) {
429
+ Tracing . popActivity ( handlerData . xhr . __sentry_xhr_activity_id__ , handlerData . xhr . __sentry_xhr__ ) ;
430
+ return ;
431
+ }
432
+
407
433
handlerData . xhr . __sentry_xhr_activity_id__ = Tracing . pushActivity ( 'xhr' , {
408
434
data : {
409
435
request_data : xhr . data ,
0 commit comments