@@ -26,7 +26,7 @@ describe('resourceTimingToSpanAttributes', () => {
26
26
duration : 200 ,
27
27
initiatorType : 'fetch' ,
28
28
nextHopProtocol : 'h2' ,
29
- workerStart : 0 ,
29
+ workerStart : 1 ,
30
30
redirectStart : 10 ,
31
31
redirectEnd : 20 ,
32
32
fetchStart : 25 ,
@@ -276,6 +276,13 @@ describe('resourceTimingToSpanAttributes', () => {
276
276
} ) ;
277
277
278
278
it ( 'handles zero timing values' , ( ) => {
279
+ /**
280
+ * Most resource timing entries have a 0 value if the resource was requested from
281
+ * a cross-origin source which does not return a matching `Timing-Allow-Origin` header.
282
+ *
283
+ * see: https://developer.mozilla.org/en-US/docs/Web/API/Performance_API/Resource_timing#cross-origin_timing_information
284
+ */
285
+
279
286
extractNetworkProtocolSpy . mockReturnValue ( {
280
287
name : '' ,
281
288
version : 'unknown' ,
@@ -284,34 +291,36 @@ describe('resourceTimingToSpanAttributes', () => {
284
291
const mockResourceTiming = createMockResourceTiming ( {
285
292
nextHopProtocol : '' ,
286
293
redirectStart : 0 ,
287
- fetchStart : 0 ,
294
+ redirectEnd : 0 ,
295
+ workerStart : 0 ,
296
+ fetchStart : 1000100 , // fetchStart is not restricted by `Timing-Allow-Origin` header
288
297
domainLookupStart : 0 ,
289
298
domainLookupEnd : 0 ,
290
299
connectStart : 0 ,
291
- secureConnectionStart : 0 ,
292
300
connectEnd : 0 ,
301
+ secureConnectionStart : 0 ,
293
302
requestStart : 0 ,
294
303
responseStart : 0 ,
295
- responseEnd : 0 ,
304
+ responseEnd : 1000200 , // responseEnd is not restricted by `Timing-Allow-Origin` header
296
305
} ) ;
297
306
298
307
const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
299
308
300
309
expect ( result ) . toEqual ( {
301
310
'network.protocol.version' : 'unknown' ,
302
311
'network.protocol.name' : '' ,
303
- 'http.request.redirect_start' : 1000 , // (1000000 + 0) / 1000
304
- 'http.request.redirect_end' : 1000.02 ,
305
- 'http.request.worker_start' : 1000 ,
306
- 'http.request.fetch_start' : 1000 ,
307
- 'http.request.domain_lookup_start' : 1000 ,
308
- 'http.request.domain_lookup_end' : 1000 ,
309
- 'http.request.connect_start' : 1000 ,
310
- 'http.request.secure_connection_start' : 1000 ,
311
- 'http.request.connection_end' : 1000 ,
312
- 'http.request.request_start' : 1000 ,
313
- 'http.request.response_start' : 1000 ,
314
- 'http.request.response_end' : 1000 ,
312
+ 'http.request.redirect_start' : 0 ,
313
+ 'http.request.redirect_end' : 0 ,
314
+ 'http.request.worker_start' : 0 ,
315
+ 'http.request.fetch_start' : 2000.1 ,
316
+ 'http.request.domain_lookup_start' : 0 ,
317
+ 'http.request.domain_lookup_end' : 0 ,
318
+ 'http.request.connect_start' : 0 ,
319
+ 'http.request.secure_connection_start' : 0 ,
320
+ 'http.request.connection_end' : 0 ,
321
+ 'http.request.request_start' : 0 ,
322
+ 'http.request.response_start' : 0 ,
323
+ 'http.request.response_end' : 2000.2 ,
315
324
'http.request.time_to_first_byte' : 0 ,
316
325
} ) ;
317
326
} ) ;
@@ -343,7 +352,7 @@ describe('resourceTimingToSpanAttributes', () => {
343
352
'network.protocol.name' : 'http' ,
344
353
'http.request.redirect_start' : 1000.005 ,
345
354
'http.request.redirect_end' : 1000.02 ,
346
- 'http.request.worker_start' : 1000 ,
355
+ 'http.request.worker_start' : 1000.001 ,
347
356
'http.request.fetch_start' : 1000.01 ,
348
357
'http.request.domain_lookup_start' : 1000.015 ,
349
358
'http.request.domain_lookup_end' : 1000.02 ,
@@ -470,7 +479,7 @@ describe('resourceTimingToSpanAttributes', () => {
470
479
} ) ;
471
480
472
481
describe ( 'edge cases' , ( ) => {
473
- it ( 'handles undefined timing values' , ( ) => {
482
+ it ( "doesn't include undefined timing values" , ( ) => {
474
483
browserPerformanceTimeOriginSpy . mockReturnValue ( 1000000 ) ;
475
484
476
485
extractNetworkProtocolSpy . mockReturnValue ( {
@@ -481,6 +490,7 @@ describe('resourceTimingToSpanAttributes', () => {
481
490
const mockResourceTiming = createMockResourceTiming ( {
482
491
nextHopProtocol : '' ,
483
492
redirectStart : undefined as any ,
493
+ redirectEnd : undefined as any ,
484
494
fetchStart : undefined as any ,
485
495
workerStart : undefined as any ,
486
496
domainLookupStart : undefined as any ,
@@ -498,19 +508,6 @@ describe('resourceTimingToSpanAttributes', () => {
498
508
expect ( result ) . toEqual ( {
499
509
'network.protocol.version' : 'unknown' ,
500
510
'network.protocol.name' : '' ,
501
- 'http.request.redirect_start' : 1000 , // (1000000 + 0) / 1000
502
- 'http.request.redirect_end' : 1000.02 ,
503
- 'http.request.worker_start' : 1000 ,
504
- 'http.request.fetch_start' : 1000 ,
505
- 'http.request.domain_lookup_start' : 1000 ,
506
- 'http.request.domain_lookup_end' : 1000 ,
507
- 'http.request.connect_start' : 1000 ,
508
- 'http.request.secure_connection_start' : 1000 ,
509
- 'http.request.connection_end' : 1000 ,
510
- 'http.request.request_start' : 1000 ,
511
- 'http.request.response_start' : 1000 ,
512
- 'http.request.response_end' : 1000 ,
513
- 'http.request.time_to_first_byte' : 0 ,
514
511
} ) ;
515
512
} ) ;
516
513
@@ -534,6 +531,7 @@ describe('resourceTimingToSpanAttributes', () => {
534
531
requestStart : 999999 ,
535
532
responseStart : 999999 ,
536
533
responseEnd : 999999 ,
534
+ workerStart : 999999 ,
537
535
} ) ;
538
536
539
537
const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
@@ -543,7 +541,7 @@ describe('resourceTimingToSpanAttributes', () => {
543
541
'network.protocol.name' : '' ,
544
542
'http.request.redirect_start' : 1999.999 , // (1000000 + 999999) / 1000
545
543
'http.request.redirect_end' : 1000.02 ,
546
- 'http.request.worker_start' : 1000 ,
544
+ 'http.request.worker_start' : 1999.999 ,
547
545
'http.request.fetch_start' : 1999.999 ,
548
546
'http.request.domain_lookup_start' : 1999.999 ,
549
547
'http.request.domain_lookup_end' : 1999.999 ,
0 commit comments