zipkin-js-instrumentation-axios
Adds Zipkin tracing support for the axios JS HTTP client library. It supports all features of axios
.
Installation
npm install zipkin-js-instrumentation-axios --save
Usage
You need to use wrapAxios
fucntion 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:
const axios = ;const wrapAxios = ;const Tracer ExplicitContext ConsoleRecorder = ; const ctxImpl = ;const recorder = ;const localServiceName = 'service-a'; // name of this applicationconst tracer = ctxImpl recorder localServiceName ; const remoteServiceName = 'weather-api';const zipkinAxios = ; zipkinAxios ;
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;
The test cases all passed:
axios instrumentation - integration test
✓ should add headers to requests
✓ should support request shorthand (defaults to GET)
✓ should support both url and uri options
✓ should support promise callback
✓ should report 404 when path does not exist
✓ should report when service does not exist (41ms)
✓ should report when service returns 400
✓ should report when service returns 500
You can go to /example
folder and run npm install && node app.js
to see the result of the example.