@@ -26,7 +26,7 @@ describe('resourceTimingToSpanAttributes', () => {
2626 duration : 200 ,
2727 initiatorType : 'fetch' ,
2828 nextHopProtocol : 'h2' ,
29- workerStart : 0 ,
29+ workerStart : 1 ,
3030 redirectStart : 10 ,
3131 redirectEnd : 20 ,
3232 fetchStart : 25 ,
@@ -276,6 +276,13 @@ describe('resourceTimingToSpanAttributes', () => {
276276 } ) ;
277277
278278 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+ 279286 extractNetworkProtocolSpy . mockReturnValue ( {
280287 name : '' ,
281288 version : 'unknown' ,
@@ -284,34 +291,36 @@ describe('resourceTimingToSpanAttributes', () => {
284291 const mockResourceTiming = createMockResourceTiming ( {
285292 nextHopProtocol : '' ,
286293 redirectStart : 0 ,
287- fetchStart : 0 ,
294+ redirectEnd : 0 ,
295+ workerStart : 0 ,
296+ fetchStart : 1000100 , // fetchStart is not restricted by `Timing-Allow-Origin` header
288297 domainLookupStart : 0 ,
289298 domainLookupEnd : 0 ,
290299 connectStart : 0 ,
291- secureConnectionStart : 0 ,
292300 connectEnd : 0 ,
301+ secureConnectionStart : 0 ,
293302 requestStart : 0 ,
294303 responseStart : 0 ,
295- responseEnd : 0 ,
304+ responseEnd : 1000200 , // responseEnd is not restricted by `Timing-Allow-Origin` header
296305 } ) ;
297306
298307 const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
299308
300309 expect ( result ) . toEqual ( {
301310 'network.protocol.version' : 'unknown' ,
302311 '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 ,
315324 'http.request.time_to_first_byte' : 0 ,
316325 } ) ;
317326 } ) ;
@@ -343,7 +352,7 @@ describe('resourceTimingToSpanAttributes', () => {
343352 'network.protocol.name' : 'http' ,
344353 'http.request.redirect_start' : 1000.005 ,
345354 'http.request.redirect_end' : 1000.02 ,
346- 'http.request.worker_start' : 1000 ,
355+ 'http.request.worker_start' : 1000.001 ,
347356 'http.request.fetch_start' : 1000.01 ,
348357 'http.request.domain_lookup_start' : 1000.015 ,
349358 'http.request.domain_lookup_end' : 1000.02 ,
@@ -470,7 +479,7 @@ describe('resourceTimingToSpanAttributes', () => {
470479 } ) ;
471480
472481 describe ( 'edge cases' , ( ) => {
473- it ( 'handles undefined timing values' , ( ) => {
482+ it ( "doesn't include undefined timing values" , ( ) => {
474483 browserPerformanceTimeOriginSpy . mockReturnValue ( 1000000 ) ;
475484
476485 extractNetworkProtocolSpy . mockReturnValue ( {
@@ -481,6 +490,7 @@ describe('resourceTimingToSpanAttributes', () => {
481490 const mockResourceTiming = createMockResourceTiming ( {
482491 nextHopProtocol : '' ,
483492 redirectStart : undefined as any ,
493+ redirectEnd : undefined as any ,
484494 fetchStart : undefined as any ,
485495 workerStart : undefined as any ,
486496 domainLookupStart : undefined as any ,
@@ -498,19 +508,6 @@ describe('resourceTimingToSpanAttributes', () => {
498508 expect ( result ) . toEqual ( {
499509 'network.protocol.version' : 'unknown' ,
500510 '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 ,
514511 } ) ;
515512 } ) ;
516513
@@ -534,6 +531,7 @@ describe('resourceTimingToSpanAttributes', () => {
534531 requestStart : 999999 ,
535532 responseStart : 999999 ,
536533 responseEnd : 999999 ,
534+ workerStart : 999999 ,
537535 } ) ;
538536
539537 const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
@@ -543,7 +541,7 @@ describe('resourceTimingToSpanAttributes', () => {
543541 'network.protocol.name' : '' ,
544542 'http.request.redirect_start' : 1999.999 , // (1000000 + 999999) / 1000
545543 'http.request.redirect_end' : 1000.02 ,
546- 'http.request.worker_start' : 1000 ,
544+ 'http.request.worker_start' : 1999.999 ,
547545 'http.request.fetch_start' : 1999.999 ,
548546 'http.request.domain_lookup_start' : 1999.999 ,
549547 'http.request.domain_lookup_end' : 1999.999 ,
0 commit comments