Expected behavior
Traceparent.validate doesn't throw an exception on generated traceIds
Actual behavior
Traceparent.validate sometimes throws an exception on generated traceIds if they are not 32 characters long
Traceparent.validate requires traceIds to be 32 characters long, however those created by TelemetryCorrelationUtils are not guaranteed to be 32 characters long, the current code is as follows:
private static String generateRootId() {
UUID guid = UUID.randomUUID();
long least = guid.getLeastSignificantBits();
long most = guid.getMostSignificantBits();
return Long.toHexString(most) + Long.toHexString(least);
}
This generates 32 char ids most of the time, (e.g. for UUIDs of "bb1141ac-f798-4a6c-1234-76774462e31f") but if the generated UUID contains multiple 0s in a row (e.g. bb1141ac-f798-4a6c-0000-76774462e31f) it omits the 0s in the generated id (i.e. it generates bb1141acf7984a6c76774462e31f) which is only 28 characters long which subsequently throws the exception in Traceparent.validate
Maybe the generateRootId should be:
private static String generateRootId() {
return UUID.randomUUID().toString().replace("-", "");
}
Expected behavior
Traceparent.validate doesn't throw an exception on generated traceIds
Actual behavior
Traceparent.validate sometimes throws an exception on generated traceIds if they are not 32 characters long
Traceparent.validate requires traceIds to be 32 characters long, however those created by TelemetryCorrelationUtils are not guaranteed to be 32 characters long, the current code is as follows:
This generates 32 char ids most of the time, (e.g. for UUIDs of "bb1141ac-f798-4a6c-1234-76774462e31f") but if the generated UUID contains multiple 0s in a row (e.g. bb1141ac-f798-4a6c-0000-76774462e31f) it omits the 0s in the generated id (i.e. it generates bb1141acf7984a6c76774462e31f) which is only 28 characters long which subsequently throws the exception in Traceparent.validate
Maybe the generateRootId should be: