Adds Zipkin tracing to the request and request-promise libraries.
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.
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);
});
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);
});