Only check one part of trace ID is valid since it guarantees a value … (#3291)

* Only check one part of trace ID is valid since it guarantees a value full ID.

* Valid 64-bit IDs.
This commit is contained in:
Anuraag Agrawal 2021-06-10 21:47:36 +09:00 committed by GitHub
parent 81e2777114
commit 7ecb2e260e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 7 deletions

View File

@ -31,12 +31,11 @@ enum AndroidFriendlyRandomIdGenerator implements IdGenerator {
@Override @Override
public String generateTraceId() { public String generateTraceId() {
long idHi; long idHi = random.nextLong();
long idLo; long idLo;
do { do {
idHi = random.nextLong();
idLo = random.nextLong(); idLo = random.nextLong();
} while (idHi == INVALID_ID && idLo == INVALID_ID); } while (idLo == INVALID_ID);
return TraceId.fromLongs(idHi, idLo); return TraceId.fromLongs(idHi, idLo);
} }
} }

View File

@ -26,13 +26,12 @@ enum RandomIdGenerator implements IdGenerator {
@Override @Override
public String generateTraceId() { public String generateTraceId() {
long idHi;
long idLo;
ThreadLocalRandom random = ThreadLocalRandom.current(); ThreadLocalRandom random = ThreadLocalRandom.current();
long idHi = random.nextLong();
long idLo;
do { do {
idHi = random.nextLong();
idLo = random.nextLong(); idLo = random.nextLong();
} while (idHi == INVALID_ID && idLo == INVALID_ID); } while (idLo == INVALID_ID);
return TraceId.fromLongs(idHi, idLo); return TraceId.fromLongs(idHi, idLo);
} }
} }