@@ -110,11 +110,16 @@ describe('resourceTimingToSpanAttributes', () => {
110
110
global . performance = originalPerformance ;
111
111
} ) ;
112
112
113
- it ( 'should not extract network protocol when nextHopProtocol is empty' , ( ) => {
113
+ it ( 'should extract network protocol even when nextHopProtocol is empty' , ( ) => {
114
114
const mockResourceTiming = createMockResourceTiming ( {
115
115
nextHopProtocol : '' ,
116
116
} ) ;
117
117
118
+ extractNetworkProtocolSpy . mockReturnValue ( {
119
+ name : '' ,
120
+ version : 'unknown' ,
121
+ } ) ;
122
+
118
123
browserPerformanceTimeOriginSpy . mockReturnValue ( null ) ;
119
124
120
125
// Mock performance.timeOrigin to be undefined to ensure early return
@@ -126,8 +131,11 @@ describe('resourceTimingToSpanAttributes', () => {
126
131
127
132
const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
128
133
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
+ ] ) ;
131
139
132
140
// Restore global performance
133
141
global . performance = originalPerformance ;
@@ -188,11 +196,16 @@ describe('resourceTimingToSpanAttributes', () => {
188
196
global . performance = originalPerformance ;
189
197
} ) ;
190
198
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' , ( ) => {
192
200
const mockResourceTiming = createMockResourceTiming ( {
193
201
nextHopProtocol : '' ,
194
202
} ) ;
195
203
204
+ extractNetworkProtocolSpy . mockReturnValue ( {
205
+ name : '' ,
206
+ version : 'unknown' ,
207
+ } ) ;
208
+
196
209
browserPerformanceTimeOriginSpy . mockReturnValue ( null ) ;
197
210
198
211
// Mock performance.timeOrigin to be undefined to ensure early return
@@ -204,7 +217,10 @@ describe('resourceTimingToSpanAttributes', () => {
204
217
205
218
const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
206
219
207
- expect ( result ) . toEqual ( [ ] ) ;
220
+ expect ( result ) . toEqual ( [
221
+ [ 'network.protocol.version' , 'unknown' ] ,
222
+ [ 'network.protocol.name' , '' ] ,
223
+ ] ) ;
208
224
209
225
// Restore global performance
210
226
global . performance = originalPerformance ;
@@ -255,6 +271,11 @@ describe('resourceTimingToSpanAttributes', () => {
255
271
} ) ;
256
272
257
273
it ( 'should handle zero timing values' , ( ) => {
274
+ extractNetworkProtocolSpy . mockReturnValue ( {
275
+ name : '' ,
276
+ version : 'unknown' ,
277
+ } ) ;
278
+
258
279
const mockResourceTiming = createMockResourceTiming ( {
259
280
nextHopProtocol : '' ,
260
281
redirectStart : 0 ,
@@ -272,6 +293,8 @@ describe('resourceTimingToSpanAttributes', () => {
272
293
const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
273
294
274
295
expect ( result ) . toEqual ( [
296
+ [ 'network.protocol.version' , 'unknown' ] ,
297
+ [ 'network.protocol.name' , '' ] ,
275
298
[ 'http.request.redirect_start' , 1000 ] , // (1000000 + 0) / 1000
276
299
[ 'http.request.fetch_start' , 1000 ] ,
277
300
[ 'http.request.domain_lookup_start' , 1000 ] ,
@@ -329,6 +352,11 @@ describe('resourceTimingToSpanAttributes', () => {
329
352
// Mock browserPerformanceTimeOrigin to return null for the main check
330
353
browserPerformanceTimeOriginSpy . mockReturnValue ( null ) ;
331
354
355
+ extractNetworkProtocolSpy . mockReturnValue ( {
356
+ name : '' ,
357
+ version : 'unknown' ,
358
+ } ) ;
359
+
332
360
const mockResourceTiming = createMockResourceTiming ( {
333
361
nextHopProtocol : '' ,
334
362
redirectStart : 20 ,
@@ -345,14 +373,22 @@ describe('resourceTimingToSpanAttributes', () => {
345
373
346
374
const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
347
375
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
+ ] ) ;
350
381
} ) ;
351
382
352
383
it ( 'should use performance.timeOrigin fallback in getAbsoluteTime when available' , ( ) => {
353
384
// Mock browserPerformanceTimeOrigin to return 500000 for the main check
354
385
browserPerformanceTimeOriginSpy . mockReturnValue ( 500000 ) ;
355
386
387
+ extractNetworkProtocolSpy . mockReturnValue ( {
388
+ name : '' ,
389
+ version : 'unknown' ,
390
+ } ) ;
391
+
356
392
const mockResourceTiming = createMockResourceTiming ( {
357
393
nextHopProtocol : '' ,
358
394
redirectStart : 20 ,
@@ -370,6 +406,8 @@ describe('resourceTimingToSpanAttributes', () => {
370
406
const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
371
407
372
408
expect ( result ) . toEqual ( [
409
+ [ 'network.protocol.version' , 'unknown' ] ,
410
+ [ 'network.protocol.name' , '' ] ,
373
411
[ 'http.request.redirect_start' , 500.02 ] , // (500000 + 20) / 1000
374
412
[ 'http.request.fetch_start' , 500.04 ] , // (500000 + 40) / 1000
375
413
[ 'http.request.domain_lookup_start' , 500.06 ] , // (500000 + 60) / 1000
@@ -386,6 +424,11 @@ describe('resourceTimingToSpanAttributes', () => {
386
424
it ( 'should handle case when neither browserPerformanceTimeOrigin nor performance.timeOrigin is available' , ( ) => {
387
425
browserPerformanceTimeOriginSpy . mockReturnValue ( null ) ;
388
426
427
+ extractNetworkProtocolSpy . mockReturnValue ( {
428
+ name : '' ,
429
+ version : 'unknown' ,
430
+ } ) ;
431
+
389
432
// Mock performance.timeOrigin as undefined
390
433
const originalPerformance = global . performance ;
391
434
global . performance = {
@@ -399,8 +442,11 @@ describe('resourceTimingToSpanAttributes', () => {
399
442
400
443
const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
401
444
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
+ ] ) ;
404
450
405
451
// Restore global performance
406
452
global . performance = originalPerformance ;
@@ -411,6 +457,11 @@ describe('resourceTimingToSpanAttributes', () => {
411
457
it ( 'should handle undefined timing values' , ( ) => {
412
458
browserPerformanceTimeOriginSpy . mockReturnValue ( 1000000 ) ;
413
459
460
+ extractNetworkProtocolSpy . mockReturnValue ( {
461
+ name : '' ,
462
+ version : 'unknown' ,
463
+ } ) ;
464
+
414
465
const mockResourceTiming = createMockResourceTiming ( {
415
466
nextHopProtocol : '' ,
416
467
redirectStart : undefined as any ,
@@ -428,6 +479,8 @@ describe('resourceTimingToSpanAttributes', () => {
428
479
const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
429
480
430
481
expect ( result ) . toEqual ( [
482
+ [ 'network.protocol.version' , 'unknown' ] ,
483
+ [ 'network.protocol.name' , '' ] ,
431
484
[ 'http.request.redirect_start' , 1000 ] , // (1000000 + 0) / 1000
432
485
[ 'http.request.fetch_start' , 1000 ] ,
433
486
[ 'http.request.domain_lookup_start' , 1000 ] ,
@@ -444,6 +497,11 @@ describe('resourceTimingToSpanAttributes', () => {
444
497
it ( 'should handle very large timing values' , ( ) => {
445
498
browserPerformanceTimeOriginSpy . mockReturnValue ( 1000000 ) ;
446
499
500
+ extractNetworkProtocolSpy . mockReturnValue ( {
501
+ name : '' ,
502
+ version : 'unknown' ,
503
+ } ) ;
504
+
447
505
const mockResourceTiming = createMockResourceTiming ( {
448
506
nextHopProtocol : '' ,
449
507
redirectStart : 999999 ,
@@ -461,6 +519,8 @@ describe('resourceTimingToSpanAttributes', () => {
461
519
const result = resourceTimingToSpanAttributes ( mockResourceTiming ) ;
462
520
463
521
expect ( result ) . toEqual ( [
522
+ [ 'network.protocol.version' , 'unknown' ] ,
523
+ [ 'network.protocol.name' , '' ] ,
464
524
[ 'http.request.redirect_start' , 1999.999 ] , // (1000000 + 999999) / 1000
465
525
[ 'http.request.fetch_start' , 1999.999 ] ,
466
526
[ 'http.request.domain_lookup_start' , 1999.999 ] ,
0 commit comments