@@ -110,11 +110,16 @@ describe('resourceTimingToSpanAttributes', () => {
110110 global . performance = originalPerformance ;
111111 } ) ;
112112
113- it ( 'should not extract network protocol when nextHopProtocol is empty' , ( ) => {
113+ it ( 'should extract network protocol even when nextHopProtocol is empty' , ( ) => {
114114 const mockResourceTiming = createMockResourceTiming ( {
115115 nextHopProtocol : '' ,
116116 } ) ;
117117
118+ extractNetworkProtocolSpy . mockReturnValue ( {
119+ name : '' ,
120+ version : 'unknown' ,
121+ } ) ;
122+
118123 browserPerformanceTimeOriginSpy . mockReturnValue ( null ) ;
119124
120125 // Mock performance.timeOrigin to be undefined to ensure early return
@@ -126,8 +131,11 @@ describe('resourceTimingToSpanAttributes', () => {
126131
127132 const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
128133
129- expect ( extractNetworkProtocolSpy ) . not . toHaveBeenCalled ( ) ;
130- expect ( result ) . toEqual ( [ ] ) ;
134+ expect ( extractNetworkProtocolSpy ) . toHaveBeenCalledWith ( '' ) ;
135+ expect ( result ) . toEqual ( [
136+ [ 'network.protocol.version' , 'unknown' ] ,
137+ [ 'network.protocol.name' , '' ] ,
138+ ] ) ;
131139
132140 // Restore global performance
133141 global . performance = originalPerformance ;
@@ -188,11 +196,16 @@ describe('resourceTimingToSpanAttributes', () => {
188196 global . performance = originalPerformance ;
189197 } ) ;
190198
191- it ( 'should return empty array when no network protocol and no browserPerformanceTimeOrigin' , ( ) => {
199+ it ( 'should return network protocol attributes even when empty string and no browserPerformanceTimeOrigin' , ( ) => {
192200 const mockResourceTiming = createMockResourceTiming ( {
193201 nextHopProtocol : '' ,
194202 } ) ;
195203
204+ extractNetworkProtocolSpy . mockReturnValue ( {
205+ name : '' ,
206+ version : 'unknown' ,
207+ } ) ;
208+
196209 browserPerformanceTimeOriginSpy . mockReturnValue ( null ) ;
197210
198211 // Mock performance.timeOrigin to be undefined to ensure early return
@@ -204,7 +217,10 @@ describe('resourceTimingToSpanAttributes', () => {
204217
205218 const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
206219
207- expect ( result ) . toEqual ( [ ] ) ;
220+ expect ( result ) . toEqual ( [
221+ [ 'network.protocol.version' , 'unknown' ] ,
222+ [ 'network.protocol.name' , '' ] ,
223+ ] ) ;
208224
209225 // Restore global performance
210226 global . performance = originalPerformance ;
@@ -255,6 +271,11 @@ describe('resourceTimingToSpanAttributes', () => {
255271 } ) ;
256272
257273 it ( 'should handle zero timing values' , ( ) => {
274+ extractNetworkProtocolSpy . mockReturnValue ( {
275+ name : '' ,
276+ version : 'unknown' ,
277+ } ) ;
278+
258279 const mockResourceTiming = createMockResourceTiming ( {
259280 nextHopProtocol : '' ,
260281 redirectStart : 0 ,
@@ -272,6 +293,8 @@ describe('resourceTimingToSpanAttributes', () => {
272293 const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
273294
274295 expect ( result ) . toEqual ( [
296+ [ 'network.protocol.version' , 'unknown' ] ,
297+ [ 'network.protocol.name' , '' ] ,
275298 [ 'http.request.redirect_start' , 1000 ] , // (1000000 + 0) / 1000
276299 [ 'http.request.fetch_start' , 1000 ] ,
277300 [ 'http.request.domain_lookup_start' , 1000 ] ,
@@ -329,6 +352,11 @@ describe('resourceTimingToSpanAttributes', () => {
329352 // Mock browserPerformanceTimeOrigin to return null for the main check
330353 browserPerformanceTimeOriginSpy . mockReturnValue ( null ) ;
331354
355+ extractNetworkProtocolSpy . mockReturnValue ( {
356+ name : '' ,
357+ version : 'unknown' ,
358+ } ) ;
359+
332360 const mockResourceTiming = createMockResourceTiming ( {
333361 nextHopProtocol : '' ,
334362 redirectStart : 20 ,
@@ -345,14 +373,22 @@ describe('resourceTimingToSpanAttributes', () => {
345373
346374 const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
347375
348- // When browserPerformanceTimeOrigin returns null, function returns early without timing attributes
349- expect ( result ) . toEqual ( [ ] ) ;
376+ // When browserPerformanceTimeOrigin returns null, function returns early with only network protocol attributes
377+ expect ( result ) . toEqual ( [
378+ [ 'network.protocol.version' , 'unknown' ] ,
379+ [ 'network.protocol.name' , '' ] ,
380+ ] ) ;
350381 } ) ;
351382
352383 it ( 'should use performance.timeOrigin fallback in getAbsoluteTime when available' , ( ) => {
353384 // Mock browserPerformanceTimeOrigin to return 500000 for the main check
354385 browserPerformanceTimeOriginSpy . mockReturnValue ( 500000 ) ;
355386
387+ extractNetworkProtocolSpy . mockReturnValue ( {
388+ name : '' ,
389+ version : 'unknown' ,
390+ } ) ;
391+
356392 const mockResourceTiming = createMockResourceTiming ( {
357393 nextHopProtocol : '' ,
358394 redirectStart : 20 ,
@@ -370,6 +406,8 @@ describe('resourceTimingToSpanAttributes', () => {
370406 const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
371407
372408 expect ( result ) . toEqual ( [
409+ [ 'network.protocol.version' , 'unknown' ] ,
410+ [ 'network.protocol.name' , '' ] ,
373411 [ 'http.request.redirect_start' , 500.02 ] , // (500000 + 20) / 1000
374412 [ 'http.request.fetch_start' , 500.04 ] , // (500000 + 40) / 1000
375413 [ 'http.request.domain_lookup_start' , 500.06 ] , // (500000 + 60) / 1000
@@ -386,6 +424,11 @@ describe('resourceTimingToSpanAttributes', () => {
386424 it ( 'should handle case when neither browserPerformanceTimeOrigin nor performance.timeOrigin is available' , ( ) => {
387425 browserPerformanceTimeOriginSpy . mockReturnValue ( null ) ;
388426
427+ extractNetworkProtocolSpy . mockReturnValue ( {
428+ name : '' ,
429+ version : 'unknown' ,
430+ } ) ;
431+
389432 // Mock performance.timeOrigin as undefined
390433 const originalPerformance = global . performance ;
391434 global . performance = {
@@ -399,8 +442,11 @@ describe('resourceTimingToSpanAttributes', () => {
399442
400443 const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
401444
402- // When neither timing source is available, should return empty array
403- expect ( result ) . toEqual ( [ ] ) ;
445+ // When neither timing source is available, should return network protocol attributes for empty string
446+ expect ( result ) . toEqual ( [
447+ [ 'network.protocol.version' , 'unknown' ] ,
448+ [ 'network.protocol.name' , '' ] ,
449+ ] ) ;
404450
405451 // Restore global performance
406452 global . performance = originalPerformance ;
@@ -411,6 +457,11 @@ describe('resourceTimingToSpanAttributes', () => {
411457 it ( 'should handle undefined timing values' , ( ) => {
412458 browserPerformanceTimeOriginSpy . mockReturnValue ( 1000000 ) ;
413459
460+ extractNetworkProtocolSpy . mockReturnValue ( {
461+ name : '' ,
462+ version : 'unknown' ,
463+ } ) ;
464+
414465 const mockResourceTiming = createMockResourceTiming ( {
415466 nextHopProtocol : '' ,
416467 redirectStart : undefined as any ,
@@ -428,6 +479,8 @@ describe('resourceTimingToSpanAttributes', () => {
428479 const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
429480
430481 expect ( result ) . toEqual ( [
482+ [ 'network.protocol.version' , 'unknown' ] ,
483+ [ 'network.protocol.name' , '' ] ,
431484 [ 'http.request.redirect_start' , 1000 ] , // (1000000 + 0) / 1000
432485 [ 'http.request.fetch_start' , 1000 ] ,
433486 [ 'http.request.domain_lookup_start' , 1000 ] ,
@@ -444,6 +497,11 @@ describe('resourceTimingToSpanAttributes', () => {
444497 it ( 'should handle very large timing values' , ( ) => {
445498 browserPerformanceTimeOriginSpy . mockReturnValue ( 1000000 ) ;
446499
500+ extractNetworkProtocolSpy . mockReturnValue ( {
501+ name : '' ,
502+ version : 'unknown' ,
503+ } ) ;
504+
447505 const mockResourceTiming = createMockResourceTiming ( {
448506 nextHopProtocol : '' ,
449507 redirectStart : 999999 ,
@@ -461,6 +519,8 @@ describe('resourceTimingToSpanAttributes', () => {
461519 const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
462520
463521 expect ( result ) . toEqual ( [
522+ [ 'network.protocol.version' , 'unknown' ] ,
523+ [ 'network.protocol.name' , '' ] ,
464524 [ 'http.request.redirect_start' , 1999.999 ] , // (1000000 + 999999) / 1000
465525 [ 'http.request.fetch_start' , 1999.999 ] ,
466526 [ 'http.request.domain_lookup_start' , 1999.999 ] ,
0 commit comments