in src/plugins/AxiosPlugin.ts [61:123]
Axios.prototype.request = axios.request = function (url?: any, config?: any) {
if (typeof url === 'string') config = config ? { ...config, url } : { url };
else config = url ? { ...url } : {};
const { origin, host, pathname: operation } = new URL(config.url, config.baseURL ?? this.defaults?.baseURL);
const method = (config.method || 'GET').toUpperCase();
const span = ignoreHttpMethodCheck(method)
? DummySpan.create()
: ContextManager.current.newExitSpan(operation, Component.AXIOS, Component.HTTP);
span.start();
try {
config.headers = config.headers ? { ...config.headers } : {};
span.component = Component.AXIOS;
span.layer = SpanLayer.HTTP;
span.peer = host;
span.tag(Tag.httpURL(origin + operation));
span.tag(Tag.httpMethod(method));
span.inject().items.forEach((item) => (config.headers[item.key] = item.value));
const copyStatus = (response: any) => {
if (response) {
if (response.status) {
span.tag(Tag.httpStatusCode(response.status));
if (response.status >= 400) span.errored = true;
}
if (response.statusText) span.tag(Tag.httpStatusMsg(response.statusText));
}
};
const ret = _request.call(this, config).then(
(res: any) => {
copyStatus(res);
span.stop();
return res;
},
(err: any) => {
copyStatus(err.response);
span.error(err);
span.stop();
return Promise.reject(err);
},
);
span.async();
return ret;
} catch (err) {
span.error(err);
span.stop();
throw err;
}
};