@lark-apaas/client-toolkit 1.2.1-alpha.13 → 1.2.1-alpha.15
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/trace/index.d.ts +13 -2
- package/lib/trace/index.js +5 -2
- package/lib/utils/axiosConfig.js +15 -13
- package/package.json +1 -1
package/lib/trace/index.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { observable } from "@lark-apaas/observable-web";
|
|
2
|
+
/**
|
|
3
|
+
* 核心 Trace 方法:用于执行并追踪异步函数
|
|
4
|
+
* 使用代理模式而非直接 bind,确保在调用时获取最新的 observable 实例状态
|
|
5
|
+
*/
|
|
6
|
+
export declare const trace: (...args: Parameters<typeof observable.trace>) => Promise<unknown>;
|
|
7
|
+
/**
|
|
8
|
+
* 默认导出追踪套件
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: {
|
|
11
|
+
trace: (name: string, fn: (span: import("@opentelemetry/api").Span) => Promise<unknown>, options?: import("@opentelemetry/api").SpanOptions) => Promise<unknown>;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
package/lib/trace/index.js
CHANGED
package/lib/utils/axiosConfig.js
CHANGED
|
@@ -205,16 +205,17 @@ function initAxiosConfig(axiosInstance) {
|
|
|
205
205
|
const method = (response.config.method || 'GET').toUpperCase();
|
|
206
206
|
const cleanedPath = url.split('?')[0].replace(/^\/spark\/p\/app_\w+/, '') || '/';
|
|
207
207
|
if (span) {
|
|
208
|
-
|
|
208
|
+
const logData = {
|
|
209
209
|
method,
|
|
210
210
|
path: cleanedPath,
|
|
211
|
-
url,
|
|
212
|
-
user_agent: response.config.headers["user-agent"],
|
|
211
|
+
url: response.request?.responseURL || url || "",
|
|
213
212
|
duration_ms: startTime ? Date.now() - startTime : void 0,
|
|
214
|
-
status: response.status
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
213
|
+
status: response.status
|
|
214
|
+
};
|
|
215
|
+
if ('undefined' != typeof navigator) logData.user_agent = navigator.userAgent;
|
|
216
|
+
if (response.config.data) logData.request_body = response.config.data;
|
|
217
|
+
if (response.data) logData.response = response.data || {};
|
|
218
|
+
observable.log('INFO', safeStringify(logData), {}, span);
|
|
218
219
|
'function' == typeof span.end && span.end();
|
|
219
220
|
}
|
|
220
221
|
return response;
|
|
@@ -224,17 +225,18 @@ function initAxiosConfig(axiosInstance) {
|
|
|
224
225
|
const method = (errorConfig.method || 'GET').toUpperCase();
|
|
225
226
|
const cleanedPath = url.split('?')[0].replace(/^\/spark\/p\/app_\w+/, '') || '/';
|
|
226
227
|
if (span) {
|
|
227
|
-
|
|
228
|
+
const logData = {
|
|
228
229
|
method,
|
|
229
230
|
path: cleanedPath,
|
|
230
|
-
url,
|
|
231
|
-
user_agent: errorConfig.headers?.["user-agent"],
|
|
231
|
+
url: errorResponse.request?.responseURL || errorConfig.url || "",
|
|
232
232
|
duration_ms: startTime ? Date.now() - startTime : void 0,
|
|
233
233
|
status: errorResponse.status || 200,
|
|
234
|
-
request_body: errorConfig.data,
|
|
235
|
-
response: errorResponse.data || {},
|
|
236
234
|
error_message: errorMessage
|
|
237
|
-
}
|
|
235
|
+
};
|
|
236
|
+
if ('undefined' != typeof navigator) logData.user_agent = navigator.userAgent;
|
|
237
|
+
if (errorConfig.data) logData.request_body = errorConfig.data;
|
|
238
|
+
if (errorResponse.data) logData.response = errorResponse.data || {};
|
|
239
|
+
observable.log('ERROR', safeStringify(logData), {}, span);
|
|
238
240
|
'function' == typeof span.end && span.end();
|
|
239
241
|
}
|
|
240
242
|
return Promise.reject(error);
|