@tmsfe/tms-core 0.0.147 → 0.0.149
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/package.json +1 -1
- package/src/request.js +2 -1
- package/src/traceUtils.ts +25 -0
package/package.json
CHANGED
package/src/request.js
CHANGED
|
@@ -13,6 +13,7 @@ import { getEnvInfo, getAuthInfo } from './env';
|
|
|
13
13
|
import { safeJsonParse } from './objUtils';
|
|
14
14
|
import encryptObj from './encrypt';
|
|
15
15
|
import reporter from './report/index';
|
|
16
|
+
import { genTraceparent } from './traceUtils';
|
|
16
17
|
|
|
17
18
|
const logger = wx.getLogManager({});
|
|
18
19
|
|
|
@@ -358,7 +359,7 @@ export default class Request {
|
|
|
358
359
|
return new Promise((resolve, reject) => {
|
|
359
360
|
wx.request({
|
|
360
361
|
url: path,
|
|
361
|
-
header: { ...header, 'X-Seq-Id': seqId },
|
|
362
|
+
header: { ...header, 'X-Seq-Id': seqId, Traceparent: genTraceparent() },
|
|
362
363
|
method,
|
|
363
364
|
data,
|
|
364
365
|
enableHttp2: true,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生成traceparent Id
|
|
3
|
+
* 用途:用于生成version - trace-id - parent-id/span-id - trace-flags规则的id,方便链路追踪
|
|
4
|
+
*/
|
|
5
|
+
import { CryptoJS } from './aes';
|
|
6
|
+
|
|
7
|
+
// 生成随机的16字节trace-id和8字节parent-id/span-id
|
|
8
|
+
function generateRandomHex(size) {
|
|
9
|
+
return CryptoJS.lib.WordArray.random(size).toString(CryptoJS.enc.Hex);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 生成traceparent ID
|
|
13
|
+
function genTraceparent() {
|
|
14
|
+
const version = '00';
|
|
15
|
+
const traceId = generateRandomHex(16); // 16字节的trace-id
|
|
16
|
+
const parentId = generateRandomHex(8); // 8字节的parent-id/span-id
|
|
17
|
+
const traceFlags = '01'; // 示例标志,表示采样
|
|
18
|
+
|
|
19
|
+
const Traceparent = `${version}-${traceId}-${parentId}-${traceFlags}`;
|
|
20
|
+
return Traceparent;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
genTraceparent,
|
|
25
|
+
};
|