Created
October 19, 2018 22:29
-
-
Save danielkhan/fcb9bc539ead946b2f6f60c12d2e9123 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
Tracer, | |
BatchRecorder, | |
ExplicitContext, | |
jsonEncoder: { JSON_V2 } | |
} = require('zipkin'); | |
const zipkinMiddleware = require('zipkin-instrumentation-express').expressMiddleware; | |
const wrapRequest = require('zipkin-instrumentation-request'); | |
const request = require('request'); | |
const CLSContext = require('zipkin-context-cls'); | |
const { HttpLogger } = require('zipkin-transport-http'); | |
module.exports = (localServiceName) => { | |
const tracer = new Tracer({ | |
ctxImpl: new CLSContext('zipkin'), | |
recorder: new BatchRecorder({ | |
logger: new HttpLogger({ | |
endpoint: 'http://localhost:9411/api/v2/spans', | |
jsonEncoder: JSON_V2 | |
}) | |
}), | |
localServiceName, | |
}); | |
return { | |
middleware: () => zipkinMiddleware({ tracer }), | |
request: (remoteServiceName) => wrapRequest(request, { tracer, remoteServiceName }), | |
} | |
} | |
/* | |
// Usage: | |
// Express middleware: | |
const zipkin = require('./agent/zipkin')('<Local Service Name>'); | |
const app = express(); | |
app.use(zipkin.middleware()); | |
// To get a wrapped request object: | |
const request = zipkin.request('<Remote Service Name>'); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment