File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -402,7 +402,16 @@ export class Span implements SpanInterface {
402
402
transactionName && setBaggageValue ( baggage , 'transaction' , transactionName ) ;
403
403
userId && setBaggageValue ( baggage , 'userid' , userId ) ;
404
404
userSegment && setBaggageValue ( baggage , 'usersegment' , userSegment ) ;
405
- sampelRate && setBaggageValue ( baggage , 'samplerate' , sampelRate . toString ( ) ) ;
405
+ sampelRate &&
406
+ setBaggageValue (
407
+ baggage ,
408
+ 'samplerate' ,
409
+ // This will make sure that expnent notation (e.g. 1.45e-14) is converted to simple decimal representation
410
+ // Another edge case would be something like Number.NEGATIVE_INFINITY in which case we could still
411
+ // add something like .replace(/-?∞/, '0'). For the sake of saving bytes, I'll not add this until
412
+ // it becomes a problem
413
+ sampelRate . toLocaleString ( 'fullwide' , { useGrouping : false , maximumFractionDigits : 16 } ) ,
414
+ ) ;
406
415
publicKey && setBaggageValue ( baggage , 'publickey' , publicKey ) ;
407
416
traceId && setBaggageValue ( baggage , 'traceid' , traceId ) ;
408
417
Original file line number Diff line number Diff line change @@ -453,5 +453,29 @@ describe('Span', () => {
453
453
} ) ;
454
454
expect ( baggage && getThirdPartyBaggage ( baggage ) ) . toStrictEqual ( '' ) ;
455
455
} ) ;
456
+
457
+ test ( 'exponential sample rate notation is converted to decimal notation' , ( ) => {
458
+ const transaction = new Transaction (
459
+ {
460
+ name : 'tx' ,
461
+ metadata : {
462
+ transactionSampling : { rate : 1.45e-14 , method : 'client_rate' } ,
463
+ } ,
464
+ } ,
465
+ hub ,
466
+ ) ;
467
+
468
+ const baggage = transaction . getBaggage ( ) ;
469
+
470
+ expect ( baggage && isSentryBaggageEmpty ( baggage ) ) . toBe ( false ) ;
471
+ expect ( baggage && getSentryBaggageItems ( baggage ) ) . toStrictEqual ( {
472
+ release : '1.0.1' ,
473
+ environment : 'production' ,
474
+ transaction : 'tx' ,
475
+ samplerate : '0.0000000000000145' ,
476
+ traceid : expect . any ( String ) ,
477
+ } ) ;
478
+ expect ( baggage && getThirdPartyBaggage ( baggage ) ) . toStrictEqual ( '' ) ;
479
+ } ) ;
456
480
} ) ;
457
481
} ) ;
You can’t perform that action at this time.
0 commit comments