@@ -63,7 +63,7 @@ describe('callbacks', () => {
63
63
const fetchHandlerData : FetchData = {
64
64
args : [ 'http://dogs.are.great/' , { } ] ,
65
65
fetchData : { url : 'http://dogs.are.great/' , method : 'GET' } ,
66
- startTimestamp : 1356996072000 ,
66
+ startTimestamp : 2012112120121231 ,
67
67
} ;
68
68
const xhrHandlerData : XHRData = {
69
69
xhr : {
@@ -78,18 +78,27 @@ describe('callbacks', () => {
78
78
// setRequestHeader: XMLHttpRequest.prototype.setRequestHeader,
79
79
setRequestHeader,
80
80
} ,
81
- startTimestamp : 1353501072000 ,
81
+ startTimestamp : 2012112120121231 ,
82
82
} ;
83
- const endTimestamp = 1356996072000 ;
83
+ const endTimestamp = 2013041520130908 ;
84
84
85
85
beforeAll ( ( ) => {
86
- hub = new Hub ( new BrowserClient ( { tracesSampleRate : 1 } ) ) ;
86
+ hub = new Hub (
87
+ new BrowserClient ( {
88
+ dsn :
'https://[email protected] /12312012' ,
89
+ environment : 'dogpark' ,
90
+ release : 'off.leash.park' ,
91
+
92
+ tracesSampleRate : 1 ,
93
+ } ) ,
94
+ ) ;
87
95
makeMain ( hub ) ;
88
96
} ) ;
89
97
90
98
beforeEach ( ( ) => {
91
- transaction = hub . startTransaction ( { name : 'organizations/users/:userid ' , op : 'pageload ' } ) as Transaction ;
99
+ transaction = hub . startTransaction ( { name : 'meetNewDogFriend ' , op : 'wag.tail ' } ) as Transaction ;
92
100
hub . configureScope ( scope => scope . setSpan ( transaction ) ) ;
101
+ jest . clearAllMocks ( ) ;
93
102
} ) ;
94
103
95
104
describe ( 'fetchCallback()' , ( ) => {
@@ -117,20 +126,17 @@ describe('callbacks', () => {
117
126
expect ( spans ) . toEqual ( { } ) ;
118
127
} ) ;
119
128
120
- it ( 'does not add fetch request headers if tracing is disabled' , ( ) => {
129
+ it ( 'does not add tracing headers if tracing is disabled' , ( ) => {
121
130
hasTracingEnabled . mockReturnValueOnce ( false ) ;
122
131
123
132
// make a local copy so the global one doesn't get mutated
124
- const handlerData : FetchData = {
125
- args : [ 'http://dogs.are.great/' , { } ] ,
126
- fetchData : { url : 'http://dogs.are.great/' , method : 'GET' } ,
127
- startTimestamp : 1353501072000 ,
128
- } ;
133
+ const handlerData = { ...fetchHandlerData } ;
129
134
130
135
fetchCallback ( handlerData , alwaysCreateSpan , { } ) ;
131
136
132
137
const headers = ( handlerData . args [ 1 ] . headers as Record < string , string > ) || { } ;
133
138
expect ( headers [ 'sentry-trace' ] ) . not . toBeDefined ( ) ;
139
+ expect ( headers [ 'tracestate' ] ) . not . toBeDefined ( ) ;
134
140
} ) ;
135
141
136
142
it ( 'creates and finishes fetch span on active transaction' , ( ) => {
@@ -185,8 +191,15 @@ describe('callbacks', () => {
185
191
expect ( newSpan ! . status ) . toBe ( SpanStatus . fromHttpCode ( 404 ) ) ;
186
192
} ) ;
187
193
188
- it ( 'adds sentry-trace header to fetch requests' , ( ) => {
189
- // TODO
194
+ it ( 'adds tracing headers to fetch requests' , ( ) => {
195
+ // make a local copy so the global one doesn't get mutated
196
+ const handlerData = { ...fetchHandlerData } ;
197
+
198
+ fetchCallback ( handlerData , alwaysCreateSpan , { } ) ;
199
+
200
+ const headers = ( handlerData . args [ 1 ] . headers as Record < string , string > ) || { } ;
201
+ expect ( headers [ 'sentry-trace' ] ) . toBeDefined ( ) ;
202
+ expect ( headers [ 'tracestate' ] ) . toBeDefined ( ) ;
190
203
} ) ;
191
204
} ) ;
192
205
@@ -207,21 +220,22 @@ describe('callbacks', () => {
207
220
expect ( spans ) . toEqual ( { } ) ;
208
221
} ) ;
209
222
210
- it ( 'does not add xhr request headers if tracing is disabled' , ( ) => {
223
+ it ( 'does not add tracing headers if tracing is disabled' , ( ) => {
211
224
hasTracingEnabled . mockReturnValueOnce ( false ) ;
212
225
213
226
xhrCallback ( xhrHandlerData , alwaysCreateSpan , { } ) ;
214
227
215
228
expect ( setRequestHeader ) . not . toHaveBeenCalled ( ) ;
216
229
} ) ;
217
230
218
- it ( 'adds sentry-trace header to XHR requests' , ( ) => {
231
+ it ( 'adds tracing headers to XHR requests' , ( ) => {
219
232
xhrCallback ( xhrHandlerData , alwaysCreateSpan , { } ) ;
220
233
221
234
expect ( setRequestHeader ) . toHaveBeenCalledWith (
222
235
'sentry-trace' ,
223
236
expect . stringMatching ( tracingUtils . TRACEPARENT_REGEXP ) ,
224
237
) ;
238
+ expect ( setRequestHeader ) . toHaveBeenCalledWith ( 'tracestate' , expect . any ( String ) ) ;
225
239
} ) ;
226
240
227
241
it ( 'creates and finishes XHR span on active transaction' , ( ) => {
0 commit comments