Skip to content

Commit 8bbfa35

Browse files
authored
[Synthtrace] Fix id overflow (#215199)
fixes [214636](#214636) ## Summary Fix the random id generator, it would sometimes generate an id longer than the specified length. > Error: generated id is longer than 16 characters: 17
1 parent de52f41 commit 8bbfa35

File tree

1 file changed

+4
-4
lines changed
  • src/platform/packages/shared/kbn-apm-synthtrace-client/src/lib/utils

1 file changed

+4
-4
lines changed

src/platform/packages/shared/kbn-apm-synthtrace-client/src/lib/utils/generate_id.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ function generateRandomId(length: number = LONG_ID_LENGTH) {
3434
const randomFactor = Math.floor(Math.random() * UNIQUE_ID_MAX_SEQ);
3535
const randomHex = (randomFactor * Date.now() * seq).toString(16);
3636

37-
const generatedId =
38-
randomHex.length < length
39-
? `${randomHex}${String(seq).padStart(length - randomHex.length, '0')}`
40-
: randomHex.substring(0, length);
37+
const generatedId = `${randomHex}${String(seq).padStart(
38+
length - randomHex.length,
39+
'0'
40+
)}`.substring(0, length);
4141

4242
if (generatedId.length > length) {
4343
throw new Error(`generated id is longer than ${length} characters: ${generatedId.length}`);

0 commit comments

Comments
 (0)