0.2.2 • Published 5 years ago

@alex2005git/zipkin-instrumentation-axios v0.2.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 years ago

Forked to update dependency versions.

@alex2005git/zipkin-instrumentation-axios

Library to instrument the axios HTTP-client.

You need to inject you axios instance into wrapAxios(axios, options).

Installation

npm i @alex2005git/zipkin-instrumentation-axios

Usage

// Require dependencies
const axios = require('axios');
const wrapAxios = require('zipkin-instrumentation-axios');
const { Tracer, ExplicitContext, BatchRecorder } = require('zipkin');

// Setup zipkin components
const ctxImpl = new ExplicitContext();
const recorder = new BatchRecorder({
  logger: new HttpLogger({
    endpoint: `http://localhost:9411/api/v2/spans`
  })
});
const tracer = new Tracer({ ctxImpl, recorder });

// Wrapp an instance of axios
const zipkinAxios = wrapAxios(axios, { tracer, serviceName: 'myService'});

// Fetch data with HTTP-GET
zipkinAxios.get('http://another-service/foo')
.then(result => res.send(result.data))
.catch(e => console.log(e));

// Post data
zipkinAxios.post('http://another-service/bar', { bar: 42 })
.then(result => res.send(result.data))
.catch(e => console.log(e));

Publishing

npm adduser --scope=@alex2005git
npm publish --access=public