zipkin-transport-http
This is a module that sends Zipkin trace data to a configurable HTTP endpoint.
Usage
npm install zipkin-transport-http --save
const {
Tracer,
BatchRecorder,
jsonEncoder: {JSON_V2}
} = require('zipkin');
const {HttpLogger} = require('zipkin-transport-http');
const noop = require('noop-logger');
const recorder = new BatchRecorder({
logger: new HttpLogger({
endpoint: 'http://localhost:9411/api/v2/spans',
jsonEncoder: JSON_V2,
httpInterval: 1000,
headers: {'Authorization': 'secret'},
timeout: 1000,
maxPayloadSize: 0,
agent: new http.Agent({keepAlive: true}),
log: noop,
fetchImplementation: require('node-fetch')
})
});
const tracer = new Tracer({
recorder,
ctxImpl,
localServiceName: 'service-a'
});
Options
Required
- endpoint - HTTP endpoint which spans will be sent.
Optional
- agent - HTTP(S) agent to use for any networking related options.
- Takes an http/https NodeJS Agent.
- Defaults to null
new HttpLogger({
endpoint: 'http://localhost:9411/api/v2/spans',
agent: new http.Agent({
ca: fs.readFileSync('pathToCaCert'),
cert: fs.readFileSync('pathToCert'),
key: fs.readFileSync('pathToPrivateKey')
})
})
- headers - Any additional HTTP headers to be sent with span.
- Will set
'Content-Type': 'application/json'
at a minimum
- httpInterval - How often to sync spans.
- jsonEncoder - JSON encoder to use when sending spans.
- maxPayloadSize - Max payload size for zipkin span.
- Will drop any spans exceeding this threshold.
- Defaults to 0 (Disabled)
- log - Internal logger used within the transport.
- timeout - Timeout for HTTP Post when sending spans.
- fetchImplementation - The fetch API to be used for sending spans.
-
Defaults to default global fetch or fallsback to node-fetch
.
-
A different fetch implementation can be plugged to fulfill different requirements, for example one can use fetch-retry to allow retries and exponential back-off:
const {HttpLogger} = require('zipkin-transport-http');
const fetch = require('node-fetch');
const fetchRetryBuilder = require('fetch-retry');
const fetchRetryOptions = {
retryOn: (attempt, error, response) => error !== null
|| response == null
|| response.status >= 408,
retryDelay: tryIndex => 1000 ** tryIndex
};
const fetchImplementation = fetchRetryBuilder(fetch, fetchRetryOptions);
const httpLogger = new HttpLogger({
endpoint: `http://localhost:9411/api/v1/spans`,
httpInterval: 1,
fetchImplementation
});