@tmsfe/tms-core 0.0.175 → 0.0.177

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.175",
3
+ "version": "0.0.177",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -52,7 +52,7 @@ function proxyWxRequest(): void {
52
52
  enumerable: true,
53
53
  configurable: true,
54
54
  value(options: any) {
55
- const startTime = Date.now();
55
+ let startTime = Date.now();
56
56
  const { url, method, data, header = {}, success, fail, complete, dataType, responseType } = options;
57
57
  const traceparent = genTraceparent();
58
58
  const traceId = traceparent.split('-')[1];
@@ -113,20 +113,26 @@ function proxyWxRequest(): void {
113
113
  responseType: 'arraybuffer',
114
114
  success: async (result) => {
115
115
  // 网络响应耗时
116
+ let now = Date.now();
116
117
  wx.reportEvent?.('cost_encrypt_statistic', {
117
118
  period: 'receive_data',
118
- cost: Date.now() - startTime,
119
+ cost: now - startTime,
119
120
  path: originalOptions.url,
121
+ trace_id: traceparent,
120
122
  });
123
+ startTime = now;
121
124
  const { header: resHeader, data: resData } = result;
122
125
  const { success: decSuccess, msg, res } = await encryptUtil
123
126
  .resDecrypt(traceId, resHeader, resData, cryptoKeyInfo);
124
127
  // 解密响应耗时
128
+ now = Date.now();
125
129
  wx.reportEvent?.('cost_encrypt_statistic', {
126
130
  period: 'decrypt_data',
127
- cost: Date.now() - startTime,
131
+ cost: now - startTime,
128
132
  path: originalOptions.url,
133
+ trace_id: traceparent,
129
134
  });
135
+ startTime = now;
130
136
  if (res.retry) { // 解密出现问题,需要明文重试
131
137
  util.reportFunc(url, traceparent, `解密失败:${msg}`);
132
138
  const newTraceparent = genTraceparent();
@@ -139,11 +145,14 @@ function proxyWxRequest(): void {
139
145
  });
140
146
  success?.call(this, res);
141
147
  // 接口重试耗时
148
+ let now = Date.now();
142
149
  wx.reportEvent?.('cost_encrypt_statistic', {
143
150
  period: 'retry_request',
144
151
  cost: Date.now() - startTime,
145
152
  path: originalOptions.url,
153
+ trace_id: traceparent,
146
154
  });
155
+ startTime = now;
147
156
  },
148
157
  header: { ...header, Traceparent: newTraceparent },
149
158
  });
@@ -156,11 +165,14 @@ function proxyWxRequest(): void {
156
165
  });
157
166
  success?.call(this, res);
158
167
  // 响应回调耗时
168
+ let now = Date.now();
159
169
  wx.reportEvent?.('cost_encrypt_statistic', {
160
170
  period: 'response_callback',
161
- cost: Date.now() - startTime,
171
+ cost: now - startTime,
162
172
  path: originalOptions.url,
173
+ trace_id: traceparent,
163
174
  });
175
+ startTime = now;
164
176
  } else { // 不支持明文重试,且解密失败
165
177
  util.reportFunc(url, traceparent, `解密失败:${msg}`);
166
178
  fail?.call(this, new Error(msg));
@@ -180,11 +192,14 @@ function proxyWxRequest(): void {
180
192
  },
181
193
  });
182
194
  // 加密请求准备耗时
195
+ let now = Date.now();
183
196
  wx.reportEvent?.('cost_encrypt_statistic', {
184
197
  period: 'before_request',
185
- cost: Date.now() - startTime,
198
+ cost: now - startTime,
186
199
  path: url,
200
+ trace_id: traceparent,
187
201
  });
202
+ startTime = now;
188
203
  },
189
204
  });
190
205
  }