@arms/rum-core 0.0.25-beta.11 → 0.0.25-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/utils/base.d.ts +2 -1
- package/lib/utils/base.js +19 -9
- package/package.json +1 -1
package/lib/utils/base.d.ts
CHANGED
|
@@ -15,9 +15,10 @@ export declare function generateTraceId(): string;
|
|
|
15
15
|
/**
|
|
16
16
|
* @description: 随机生成 spanId
|
|
17
17
|
* @param len {number}
|
|
18
|
+
* @param radix {number}
|
|
18
19
|
* @return {String}
|
|
19
20
|
*/
|
|
20
|
-
export declare function generateSpanId(len?: number): string;
|
|
21
|
+
export declare function generateSpanId(len?: number, radix?: number): string;
|
|
21
22
|
/**
|
|
22
23
|
* @description: 随机生成 eventId
|
|
23
24
|
* @param sessionId {string} sessionId
|
package/lib/utils/base.js
CHANGED
|
@@ -34,8 +34,18 @@ function generateGUID() {
|
|
|
34
34
|
try {
|
|
35
35
|
if (crypto && crypto.randomUUID) {
|
|
36
36
|
guid = crypto.randomUUID();
|
|
37
|
+
} else if (crypto && crypto.getRandomValues) {
|
|
38
|
+
var buf = new Uint8Array(16);
|
|
39
|
+
crypto.getRandomValues(buf);
|
|
40
|
+
buf[6] = buf[6] & 0x0f | 0x40; // version 4 UUID
|
|
41
|
+
buf[8] = buf[8] & 0x3f | 0x80; // variant 10xxxxxx
|
|
42
|
+
guid = buf.reduce(function (str, _byte) {
|
|
43
|
+
return str + _byte.toString(16).padStart(2, '0');
|
|
44
|
+
}, '').replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, '\$1-\$2-\$3-\$4-\$5');
|
|
37
45
|
}
|
|
38
|
-
} catch (e) {
|
|
46
|
+
} catch (e) {
|
|
47
|
+
//
|
|
48
|
+
}
|
|
39
49
|
if (!guid) {
|
|
40
50
|
guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
41
51
|
var r = Math.random() * 16 | 0,
|
|
@@ -65,21 +75,21 @@ function generateTraceId() {
|
|
|
65
75
|
/**
|
|
66
76
|
* @description: 随机生成 spanId
|
|
67
77
|
* @param len {number}
|
|
78
|
+
* @param radix {number}
|
|
68
79
|
* @return {String}
|
|
69
80
|
*/
|
|
70
|
-
function generateSpanId(len) {
|
|
81
|
+
function generateSpanId(len, radix) {
|
|
71
82
|
if (len === void 0) {
|
|
72
83
|
len = 16;
|
|
73
84
|
}
|
|
74
|
-
|
|
85
|
+
if (radix === void 0) {
|
|
86
|
+
radix = 16;
|
|
87
|
+
}
|
|
88
|
+
var result = '';
|
|
75
89
|
for (var i = 0; i < len; i++) {
|
|
76
|
-
|
|
77
|
-
// valid hex characters in the range 48-57 and 97-102
|
|
78
|
-
if (list[i] >= 58) {
|
|
79
|
-
list[i] += 39;
|
|
80
|
-
}
|
|
90
|
+
result += Math.floor(Math.random() * radix).toString(radix);
|
|
81
91
|
}
|
|
82
|
-
return
|
|
92
|
+
return result;
|
|
83
93
|
}
|
|
84
94
|
|
|
85
95
|
/**
|