@@ -35,26 +35,26 @@ 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
+ if ( ! _options . tracingOrigins || ! Array . isArray ( _options . tracingOrigins ) || _options . tracingOrigins . length === 0 ) {
40
+ throw new SentryError ( 'You need to define `tracingOrigins` in the options. Set an array of urls to trace.' ) ;
41
+ }
42
+ }
39
43
40
44
/**
41
45
* @inheritDoc
42
46
*/
43
47
public setupOnce ( _ : ( callback : EventProcessor ) => void , getCurrentHub : ( ) => Hub ) : void {
44
- if ( this . _options . tracingOrigins . length ) {
45
- if ( this . _options . traceXHR !== false ) {
46
- this . _traceXHR ( getCurrentHub ) ;
47
- }
48
- if ( this . _options . traceFetch !== false ) {
49
- this . _traceFetch ( getCurrentHub ) ;
50
- }
51
- if ( this . _options . autoStartOnDomReady !== false ) {
52
- getGlobalObject < Window > ( ) . addEventListener ( 'DOMContentLoaded' , ( ) => {
53
- Tracing . startTrace ( getCurrentHub ( ) , getGlobalObject < Window > ( ) . location . href ) ;
54
- } ) ;
55
- }
56
- } else {
57
- throw new SentryError ( 'You need to define tracingOrigins in the options' ) ;
48
+ if ( this . _options . traceXHR !== false ) {
49
+ this . _traceXHR ( getCurrentHub ) ;
50
+ }
51
+ if ( this . _options . traceFetch !== false ) {
52
+ this . _traceFetch ( getCurrentHub ) ;
53
+ }
54
+ if ( this . _options . autoStartOnDomReady !== false ) {
55
+ getGlobalObject < Window > ( ) . addEventListener ( 'DOMContentLoaded' , ( ) => {
56
+ Tracing . startTrace ( getCurrentHub ( ) , getGlobalObject < Window > ( ) . location . href ) ;
57
+ } ) ;
58
58
}
59
59
}
60
60
@@ -102,19 +102,19 @@ export class Tracing implements Integration {
102
102
function ( this : XMLHttpRequest , ...args : any [ ] ) : void {
103
103
// @ts -ignore
104
104
const self = getCurrentHub ( ) . getIntegration ( Tracing ) ;
105
- if ( self ) {
105
+ if ( self && self . _xhrUrl ) {
106
106
const headers = getCurrentHub ( ) . traceHeaders ( ) ;
107
107
let whiteListed = false ;
108
-
109
- if ( self . _xhrUrl ) {
110
- self . _options . tracingOrigins . forEach ( ( whiteListUrl : string ) => {
111
- if ( ! whiteListed ) {
112
- whiteListed = isMatchingPattern ( self . _xhrUrl , whiteListUrl ) ;
113
- }
114
- } ) ;
108
+ // tslint:disable-next-line: prefer-for-of
109
+ for ( let index = 0 ; index < self . _options . tracingOrigins . length ; index ++ ) {
110
+ const whiteListUrl = self . _options . tracingOrigins [ index ] ;
111
+ whiteListed = isMatchingPattern ( self . _xhrUrl , whiteListUrl ) ;
112
+ if ( whiteListed ) {
113
+ break ;
114
+ }
115
115
}
116
116
117
- if ( whiteListed ) {
117
+ if ( whiteListed && this . setRequestHeader ) {
118
118
Object . keys ( headers ) . forEach ( key => {
119
119
this . setRequestHeader ( key , headers [ key ] ) ;
120
120
} ) ;
0 commit comments