@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.
- package/lib/utils/axiosConfig.js +24 -15
- package/package.json +1 -1
package/lib/utils/axiosConfig.js
CHANGED
|
@@ -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.
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
146
|
-
|
|
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();
|