zipkin-instrumentation-request-promise

0.22.0 • Public • Published

zipkin-instrumentation-request-promise

npm

Adds Zipkin tracing to the request and request-promise libraries.

Usage

The library provides two ways to instrument your request. You have the wrapRequest function which provides an interface similar to zipkin-instrumentation-request and Request class which follow the OOP patterns. Keep in mind wrapRequest is just a wrapper around Request class, so there is no difference between the two.

Using the wrapRequest function

const {Tracer, ExplicitContext, ConsoleRecorder} = require('zipkin');
const {wrapRequest} = require('zipkin-instrumentation-request-promise');
 
const ctxImpl = new ExplicitContext();
const recorder = new ConsoleRecorder();
const localServiceName = 'service-a'; // name of this application
const tracer = new Tracer({ctxImpl, recorder, localServiceName});
 
const remoteServiceName = 'weather-api';
const request = wrapRequest(tracer, remoteServiceName);
 
request({
    url: 'http://api.weather.com',
    method: 'GET',
  })
  .then(function(body, response) {
    console.log('statusCode:', response && response.statusCode);
    console.log('body:', body);
  })
  .catch(function(err){
    console.log('error:', error);
  });

Using the Request class

const {Tracer, ExplicitContext, ConsoleRecorder} = require('zipkin');
const ZipkinRequest = require('zipkin-instrumentation-request-promise').default;
 
const ctxImpl = new ExplicitContext();
const recorder = new ConsoleRecorder();
const localServiceName = 'service-a'; // name of this application
const tracer = new Tracer({ctxImpl, recorder, localServiceName});
 
const remoteServiceName = 'weather-api';
const request = new ZipkinRequest(tracer, remoteServiceName);
 
request.get('http://api.weather.com')
  .then(function(body, response) {
    console.log('statusCode:', response && response.statusCode);
    console.log('body:', body);
  })
  .catch(function(err){
    console.log('error:', error);
  });

Readme

Keywords

none

Package Sidebar

Install

npm i zipkin-instrumentation-request-promise

Weekly Downloads

76

Version

0.22.0

License

Apache-2.0

Unpacked Size

50.8 kB

Total Files

13

Last publish

Collaborators

  • openzipkin