@@ -3,7 +3,7 @@ import { consoleSandbox, fill, getGlobalObject, isMatchingPattern, supportsNativ
3
3
4
4
/** JSDoc */
5
5
interface TracingOptions {
6
- tracingOrigins : Array < string | RegExp > ;
6
+ tracingOrigins ? : Array < string | RegExp > ;
7
7
traceXHR ?: boolean ;
8
8
traceFetch ?: boolean ;
9
9
autoStartOnDomReady ?: boolean ;
@@ -35,7 +35,7 @@ export class Tracing implements Integration {
35
35
*
36
36
* @param _options TracingOptions
37
37
*/
38
- public constructor ( private readonly _options : TracingOptions ) {
38
+ public constructor ( private readonly _options : TracingOptions = { } ) {
39
39
if ( ! Array . isArray ( _options . tracingOrigins ) || _options . tracingOrigins . length === 0 ) {
40
40
consoleSandbox ( ( ) => {
41
41
const defaultTracingOrigins = [ 'localhost' , / ^ \/ / ] ;
@@ -88,7 +88,7 @@ export class Tracing implements Integration {
88
88
* JSDoc
89
89
*/
90
90
private _traceXHR ( getCurrentHub : ( ) => Hub ) : void {
91
- if ( ! ( 'XMLHttpRequest' in global ) ) {
91
+ if ( ! ( 'XMLHttpRequest' in getGlobalObject < Window > ( ) ) ) {
92
92
return ;
93
93
}
94
94
@@ -116,11 +116,12 @@ export class Tracing implements Integration {
116
116
function ( this : XMLHttpRequest , ...args : any [ ] ) : void {
117
117
// @ts -ignore
118
118
const self = getCurrentHub ( ) . getIntegration ( Tracing ) ;
119
- if ( self && self . _xhrUrl ) {
119
+ if ( self && self . _xhrUrl && self . _options . tracingOrigins ) {
120
+ const url = self . _xhrUrl ;
120
121
const headers = getCurrentHub ( ) . traceHeaders ( ) ;
121
122
// tslint:disable-next-line: prefer-for-of
122
123
const isWhitelisted = self . _options . tracingOrigins . some ( ( origin : string | RegExp ) =>
123
- isMatchingPattern ( self . _xhrUrl , origin ) ,
124
+ isMatchingPattern ( url , origin ) ,
124
125
) ;
125
126
126
127
if ( isWhitelisted && this . setRequestHeader ) {
@@ -148,12 +149,12 @@ export class Tracing implements Integration {
148
149
return function ( ...args : any [ ] ) : void {
149
150
// @ts -ignore
150
151
const self = getCurrentHub ( ) . getIntegration ( Tracing ) ;
151
- if ( self ) {
152
+ if ( self && self . _options . tracingOrigins ) {
152
153
const url = args [ 0 ] as string ;
153
154
const options = args [ 1 ] as { [ key : string ] : any } ;
154
155
155
156
let whiteListed = false ;
156
- self . _options . tracingOrigins . forEach ( ( whiteListUrl : string ) => {
157
+ self . _options . tracingOrigins . forEach ( ( whiteListUrl : string | RegExp ) => {
157
158
if ( ! whiteListed ) {
158
159
whiteListed = isMatchingPattern ( url , whiteListUrl ) ;
159
160
}
@@ -171,7 +172,7 @@ export class Tracing implements Integration {
171
172
}
172
173
}
173
174
// tslint:disable-next-line: no-unsafe-any
174
- return originalFetch . apply ( global , args ) ;
175
+ return originalFetch . apply ( getGlobalObject < Window > ( ) , args ) ;
175
176
} ;
176
177
} ) ;
177
178
// tslint:enable: only-arrow-functions
0 commit comments