@lark-apaas/client-toolkit 1.2.1-alpha.10 → 1.2.1-alpha.11

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.
@@ -131,22 +131,31 @@ async function logResponse(ok, responseOrError) {
131
131
  const requestStacktraceMap = new Map();
132
132
  function initAxiosConfig(axiosInstance) {
133
133
  if (!axiosInstance) axiosInstance = axios;
134
- axiosInstance.interceptors.request.use((config)=>{
135
- const method = (config.method || 'GET').toUpperCase();
136
- const url = config.url || '';
137
- const cleanedPath = url.split('?')[0].replace(/^\/spark\/p\/app_\w+/, '') || '/';
138
- try {
139
- const span = observable.startSpan(`${method} ${cleanedPath}`);
140
- if (span) {
141
- const traceInfo = `${span.spanContext().traceId}-${span.spanContext().spanId}`;
142
- config.headers["X-Tt-TraceInfo"] = traceInfo;
143
- config.__span = span;
134
+ if (axiosInstance && !axiosInstance._isTraced) {
135
+ axiosInstance._isTraced = true;
136
+ const originalRequest = axiosInstance.request;
137
+ axiosInstance.request = function(urlOrConfig, config) {
138
+ try {
139
+ const finalConfig = 'string' == typeof urlOrConfig ? config = config || {} : urlOrConfig = urlOrConfig || {};
140
+ const method = (finalConfig.method || 'GET').toUpperCase();
141
+ const url = finalConfig.url || ('string' == typeof urlOrConfig ? urlOrConfig : '');
142
+ const cleanedPath = url.split('?')[0].replace(/^\/spark\/p\/app_\w+/, '') || '/';
143
+ const span = observable.startSpan(`${method} ${cleanedPath}`);
144
+ if (span) {
145
+ const spanContext = span.spanContext();
146
+ if (spanContext && spanContext.traceId) {
147
+ const traceInfo = `${spanContext.traceId}-${spanContext.spanId}`;
148
+ if (!finalConfig.headers) finalConfig.headers = {};
149
+ finalConfig.headers['X-Tt-TraceInfo'] = traceInfo;
150
+ finalConfig.__span = span;
151
+ }
152
+ }
153
+ } catch (error) {
154
+ console.error('Trace start failed:', error);
144
155
  }
145
- } catch (error) {
146
- console.error('Trace 配置失败:', error);
147
- }
148
- return config;
149
- });
156
+ return originalRequest.apply(this, arguments);
157
+ };
158
+ }
150
159
  axiosInstance.interceptors.response.use((response)=>{
151
160
  const { __span: span, _startTime: startTime, url = "" } = response.config || {};
152
161
  const method = (response.config.method || 'GET').toUpperCase();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.1-alpha.10",
3
+ "version": "1.2.1-alpha.11",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [