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:
You can intercept requests or responses before they are handled by then or catch.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Add a request interceptor axios.interceptors.request.use(function (config) { // Do something before request is sent return config; }, function (error) { // Do something with request error returnPromise.reject(error); });
// Add a response interceptor axios.interceptors.response.use(function (response) { // Do something with response data return response; }, function (error) { // Do something with response error returnPromise.reject(error); });
The test cases all passed
1 2 3 4 5 6 7 8 9
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