zipkin-instrumentation-axiosjs
Adds Zipkin tracing support for the axios JS HTTP client library. It supports all features of axios
.
Installation
npm install zipkin-instrumentation-axiosjs --save
Usage
You need to use wrapAxios
function to wrap the native axios
instance, and the axios
instance's type/functions/attributes are not affected. As a result, you can use zipkinAxios
the same as axios
For example:
- Performing a GET request
const axios = ;const wrapAxios = ;const Tracer ExplicitContext ConsoleRecorder = ; const ctxImpl = ; // the in-process contextconst recorder = ;const localServiceName = 'service-a'; // name of this applicationconst tracer = ctxImpl recorder localServiceName ; const remoteServiceName = 'weather-api'; // name of the application you are // calling (optional)const zipkinAxios = ; zipkinAxios ;
- Wrap an axios instance
let axiosInstance = axios; axiosInstance = ;
Interceptors of Axios also supported
You can intercept requests or responses before they are handled by then or catch.
// Add a request interceptoraxiosinterceptorsrequest; // Add a response interceptoraxiosinterceptorsresponse;