Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zipkin-instrumentation-axiosjs

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zipkin-instrumentation-axiosjs

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

  • 0.22.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
440
decreased by-27.63%
Maintainers
1
Weekly downloads
 
Created
Source

zipkin-instrumentation-axiosjs

npm

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 = 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
  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.

// 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);
  });

FAQs

Package last updated on 04 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc