import { INVALID_SPANID } from '@opentelemetry/api' ; export const TRACE_ID_BYTES = 16 ; const SPAN_ID_BYTES = 8 ; const EPOCH_BYTES = 4 ; const FALLBACK_SPANID = '0000000000000001' ; type RandomBytesGenerator = ( numBytes : number ) => string ; export function generateTraceId ( generateRandomBytes ) { const epoch = Math . floor ( Date . now ( ) / 1000 ) . toString ( 16 ) ; const rand = generateRandomBytes ( TRACE_ID_BYTES - EPOCH_BYTES ) ; return epoch + rand ; } export function generateSpanId ( generateRandomBytes ) { const spanId = generateRandomBytes ( SPAN_ID_BYTES ) ; if ( spanId === INVALID_SPANID ) { return FALLBACK_SPANID ; } return spanId ; }