@@ -93,10 +93,16 @@ export class Tracing implements Integration {
93
93
const url = self . _xhrUrl ;
94
94
const headers = getCurrentHub ( ) . traceHeaders ( ) ;
95
95
// tslint:disable-next-line: prefer-for-of
96
- const isWhitelisted = self . _options . tracingOrigins . some ( ( origin : string | RegExp ) =>
96
+ let isWhitelisted = self . _options . tracingOrigins . some ( ( origin : string | RegExp ) =>
97
97
isMatchingPattern ( url , origin ) ,
98
98
) ;
99
99
100
+ if ( isMatchingPattern ( url , 'sentry_key' ) ) {
101
+ // If sentry_key is in the url, it's an internal store request to sentry
102
+ // we do not want to add the trace header to store requests
103
+ isWhitelisted = false ;
104
+ }
105
+
100
106
if ( isWhitelisted && this . setRequestHeader ) {
101
107
Object . keys ( headers ) . forEach ( key => {
102
108
this . setRequestHeader ( key , headers [ key ] ) ;
@@ -121,30 +127,37 @@ export class Tracing implements Integration {
121
127
fill ( getGlobalObject < Window > ( ) , 'fetch' , function ( originalFetch : ( ) => void ) : ( ) => void {
122
128
return function ( ...args : any [ ] ) : void {
123
129
// @ts -ignore
124
- const self = getCurrentHub ( ) . getIntegration ( Tracing ) ;
130
+ const hub = getCurrentHub ( ) ;
131
+ const self = hub . getIntegration ( Tracing ) ;
125
132
if ( self && self . _options . tracingOrigins ) {
126
133
const url = args [ 0 ] as string ;
127
134
const options = ( args [ 1 ] = ( args [ 1 ] as { [ key : string ] : any } ) || { } ) ;
128
135
129
- let whiteListed = false ;
136
+ let isWhitelisted = false ;
130
137
self . _options . tracingOrigins . forEach ( ( whiteListUrl : string | RegExp ) => {
131
- if ( ! whiteListed ) {
132
- whiteListed = isMatchingPattern ( url , whiteListUrl ) ;
138
+ if ( ! isWhitelisted ) {
139
+ isWhitelisted = isMatchingPattern ( url , whiteListUrl ) ;
133
140
}
134
141
} ) ;
135
142
136
- if ( whiteListed ) {
143
+ if ( isMatchingPattern ( url , 'sentry_key' ) ) {
144
+ // If sentry_key is in the url, it's an internal store request to sentry
145
+ // we do not want to add the trace header to store requests
146
+ isWhitelisted = false ;
147
+ }
148
+
149
+ if ( isWhitelisted ) {
137
150
if ( options . headers ) {
138
151
if ( Array . isArray ( options . headers ) ) {
139
- options . headers = [ ...options . headers , ...Object . entries ( getCurrentHub ( ) . traceHeaders ( ) ) ] ;
152
+ options . headers = [ ...options . headers , ...Object . entries ( hub . traceHeaders ( ) ) ] ;
140
153
} else {
141
154
options . headers = {
142
155
...options . headers ,
143
- ...getCurrentHub ( ) . traceHeaders ( ) ,
156
+ ...hub . traceHeaders ( ) ,
144
157
} ;
145
158
}
146
159
} else {
147
- options . headers = getCurrentHub ( ) . traceHeaders ( ) ;
160
+ options . headers = hub . traceHeaders ( ) ;
148
161
}
149
162
}
150
163
}
0 commit comments