@@ -18,6 +18,7 @@ import type { ActionEventMapper } from '../eventMappers/actionEventMapper';
1818import type { ErrorEventMapper } from '../eventMappers/errorEventMapper' ;
1919import type { ResourceEventMapper } from '../eventMappers/resourceEventMapper' ;
2020import { TracingIdType } from '../instrumentation/resourceTracking/distributedTracing/TracingIdentifier' ;
21+ import { TracingIdentifierUtils } from '../instrumentation/resourceTracking/distributedTracing/__tests__/__utils__/TracingIdentifierUtils' ;
2122import { ErrorSource , PropagatorType , RumActionType } from '../types' ;
2223
2324jest . mock ( '../../utils/time-provider/DefaultTimeProvider' , ( ) => {
@@ -451,17 +452,33 @@ describe('DdRum', () => {
451452 } ) ;
452453
453454 describe ( 'DdRum.generateUUID' , ( ) => {
454- it ( 'generates a valid trace id in decimal format' , ( ) => {
455- const traceUUID = DdRum . generateUUID ( TracingIdType . trace ) ;
455+ it ( 'generates a valid trace id in paddedHex format' , ( ) => {
456+ const uuid = DdRum . generateUUID ( TracingIdType . trace ) ;
456457
457- expect ( traceUUID ) . toBeDefined ( ) ; // Ensure the value is defined
458- expect ( BigInt ( traceUUID ) . greater ( BigInt ( 0 ) ) ) . toBe ( true ) ; // Ensure it's a valid positive number
458+ expect ( uuid ) . toBeDefined ( ) ; // Ensure the value is defined
459+ expect ( BigInt ( uuid , 16 ) . greater ( BigInt ( 0 ) ) ) . toBe ( true ) ; // Ensure it's a valid positive number
460+ expect ( TracingIdentifierUtils . isWithin128Bits ( uuid ) ) . toBe ( true ) ; // Ensure the value is within 128 bits
461+ expect ( uuid ) . toMatch ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ; // Ensure the value is in paddedHex format
459462 } ) ;
463+
460464 it ( 'generates a valid span id in decimal format' , ( ) => {
461- const spanUUID = DdRum . generateUUID ( TracingIdType . span ) ;
465+ const uuid = DdRum . generateUUID ( TracingIdType . span ) ;
466+
467+ expect ( uuid ) . toBeDefined ( ) ; // Ensure the value is defined
468+ expect ( BigInt ( uuid ) . greater ( BigInt ( 0 ) ) ) . toBe ( true ) ; // Ensure it's a valid positive number
469+ expect ( TracingIdentifierUtils . isWithin64Bits ( uuid ) ) . toBe ( true ) ; // Ensure the value is within 64 bits
470+ expect ( uuid ) . toMatch ( / ^ [ 0 - 9 ] + $ / ) ; // Ensure the value contains only decimal digits
471+ } ) ;
472+
473+ it ( 'falls back to 64 bit span id when wrong tracingIdType is passed' , ( ) => {
474+ const uuid = DdRum . generateUUID (
475+ ( 'wrong' as unknown ) as TracingIdType
476+ ) ;
462477
463- expect ( spanUUID ) . toBeDefined ( ) ;
464- expect ( BigInt ( spanUUID ) . greater ( BigInt ( 0 ) ) ) . toBe ( true ) ;
478+ expect ( uuid ) . toBeDefined ( ) ; // Ensure the value is defined
479+ expect ( BigInt ( uuid ) . greater ( BigInt ( 0 ) ) ) . toBe ( true ) ; // Ensure it's a valid positive number
480+ expect ( TracingIdentifierUtils . isWithin64Bits ( uuid ) ) . toBe ( true ) ; // Ensure the value is within 64 bits
481+ expect ( uuid ) . toMatch ( / ^ [ 0 - 9 ] + $ / ) ; // Ensure the value contains only decimal digits
465482 } ) ;
466483 } ) ;
467484
0 commit comments