1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.RandomIdGenerator = void 0;
|
4 | const SPAN_ID_BYTES = 8;
|
5 | const TRACE_ID_BYTES = 16;
|
6 |
|
7 |
|
8 |
|
9 | class RandomIdGenerator {
|
10 | constructor() {
|
11 | |
12 |
|
13 |
|
14 |
|
15 | this.generateTraceId = getIdGenerator(TRACE_ID_BYTES);
|
16 | |
17 |
|
18 |
|
19 |
|
20 | this.generateSpanId = getIdGenerator(SPAN_ID_BYTES);
|
21 | }
|
22 | }
|
23 | exports.RandomIdGenerator = RandomIdGenerator;
|
24 | const SHARED_CHAR_CODES_ARRAY = Array(32);
|
25 | function getIdGenerator(bytes) {
|
26 | return function generateId() {
|
27 | for (let i = 0; i < bytes * 2; i++) {
|
28 | SHARED_CHAR_CODES_ARRAY[i] = Math.floor(Math.random() * 16) + 48;
|
29 |
|
30 | if (SHARED_CHAR_CODES_ARRAY[i] >= 58) {
|
31 | SHARED_CHAR_CODES_ARRAY[i] += 39;
|
32 | }
|
33 | }
|
34 | return String.fromCharCode.apply(null, SHARED_CHAR_CODES_ARRAY.slice(0, bytes * 2));
|
35 | };
|
36 | }
|
37 |
|
\ | No newline at end of file |