# zipkin-instrumentation-axiosjs

> Library to instrument the axios HTTP-client to support zipkin.

Latest version **0.22.0** (published 2020-06-04) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install zipkin-instrumentation-axiosjs
pnpm add zipkin-instrumentation-axiosjs
yarn add zipkin-instrumentation-axiosjs
bun add zipkin-instrumentation-axiosjs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.22.0 |
| Published | 2020-06-04 |
| First published | 2019-03-30 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 18 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | OpenZipkin |
| Maintainers | geekeren |

## Links

- npm: https://www.npmjs.com/package/zipkin-instrumentation-axiosjs
- Repository: https://github.com/openzipkin/zipkin-js
- Homepage: https://github.com/openzipkin/zipkin-js#readme
- Issues: https://github.com/openzipkin/zipkin-js/issues
- npm.io page: https://npm.io/package/zipkin-instrumentation-axiosjs

## Dependencies (1)

- [zipkin](https://npm.io/package/zipkin.md) ^0.22.0

## Recent versions

- 0.22.0 (latest) — 2020-06-04
- 0.22.1-alpha.6 (canary) — 2021-03-01
- 0.22.1-alpha.3 — 2020-11-03
- 0.21.0 — 2020-04-16
- 0.20.0 — 2020-03-25
- 0.19.2 — 2020-02-06
- 0.19.2-alpha.6 — 2020-02-06
- 0.19.2-alpha.3 — 2020-01-30
- 0.19.2-alpha.1 — 2019-10-25
- 0.19.1 — 2019-10-16
- 0.20.0-alpha.1 — 2019-08-09
- 0.20.0-alpha.0 — 2019-08-09
- 0.19.0 — 2019-08-07
- 0.18.6 — 2019-07-24
- 0.18.5 — 2019-07-12
- … 7 more at https://npm.io/package/zipkin-instrumentation-axiosjs/versions

## README

# zipkin-instrumentation-axiosjs

![npm](https://img.shields.io/npm/dm/zipkin-instrumentation-axiosjs.svg)

Adds Zipkin tracing support for the [axios](https://www.npmjs.com/package/axios) JS HTTP client library. It **supports all features of `axios`**.

## Installation

```shell
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

```javascript
const axios = require('axios');
const wrapAxios = require('zipkin-instrumentation-axiosjs');
const { Tracer, ExplicitContext, ConsoleRecorder } = require('zipkin');

const ctxImpl = new ExplicitContext(); // the in-process context
const recorder = new ConsoleRecorder();
const localServiceName = 'service-a'; // name of this application
const tracer = new Tracer({ ctxImpl, recorder, localServiceName });

const remoteServiceName = 'weather-api'; // name of the application you are
                                         // calling (optional)
const zipkinAxios = wrapAxios(axios, { tracer, remoteServiceName });

zipkinAxios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
```

- Wrap an axios instance

```javascript
  let axiosInstance = axios.create({
    baseURL: 'https://some-domain.com/api/',
    timeout: 1000,
    headers: {'X-Custom-Header': 'foobar'}
});
  axiosInstance = wrapAxios(axiosInstance, {tracer, remoteServiceName});
```


### Interceptors of Axios also supported

You can intercept requests or responses before they are handled by then or catch.

```javascript
// 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
    return Promise.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
    return Promise.reject(error);
  });
```

---
_Source: https://npm.io/package/zipkin-instrumentation-axiosjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
