Convenience wrapper for
got
to that adds opentracing spans to the request.
Copied then adapted for opentracing from gl-got Assumes you already use opentracing-javascript in your project.
$ npm install --save ot-got
or
$ yarn add ot-got
This package can be used like you would use normal got
with the exception of if you want to trace the requests, you must add a config, like so:
const otGot = require('ot-got');
otGot('https://your-microservice.io', {
tracingOptions: {
parentSpan: span,
injectHeaders: true
}
}).then(res => {
// response
});
Same as got
(including the stream API and aliases), but with some additional options below.
Type: object
Shared config for all your tracing. See below for possible properties.
Type: Tracer
Default: globalTracer()
Can be set manually, but if not this will use the opentracing package globalTracer()
function.
Type: Span
Passes in a span used as childOf
ref to the span we create in ot-got for requests.
Type: boolean
Default: false
Wether you want the client do close the parent span or not
Type: boolean
Default: false
Wether you want the client to inject headers to the request or not. By doing this the service you are calling will be able to continue the trace.
MIT © Sindre Sorhus © Fredrik Pettersen