Skip to content

Instantly share code, notes, and snippets.

@DanielMSchmidt
Last active May 31, 2017 09:37
Show Gist options
  • Save DanielMSchmidt/d3fc48cf3d0f03f5b72ccf99b2569ccd to your computer and use it in GitHub Desktop.
Save DanielMSchmidt/d3fc48cf3d0f03f5b72ccf99b2569ccd to your computer and use it in GitHub Desktop.
Minimal example of how to use zipkin
const express = require('express');
const { BatchRecorder, Tracer, Annotation, ExplicitContext } = require('zipkin');
const { HttpLogger } = require('zipkin-transport-http');
const tracer = new Tracer({
ctxImpl: new ExplicitContext(),
recorder: new BatchRecorder({
logger: new HttpLogger({
endpoint: 'http://localhost:9411/api/v1/spans',
}),
}),
});
const app = express();
app.use(function zipkinExpressMiddleware(req, res, next) {
tracer.scoped(() => {
tracer.setId(tracer.createRootId());
const id = tracer.id;
tracer.recordServiceName('FOO');
setTimeout(() => {
tracer.scoped(() => {
tracer.setId(id);
tracer.recordAnnotation(new Annotation.ServerSend());
});
}, 100);
next();
});
});
app.get('/', (req, res) => {
res.send(Date.now().toString());
});
app.listen(8081, () => {
console.log('Frontend listening on port 8081!');
});
{
"scripts": {
"start": "node index.js",
"startZipkin": "docker run -d -p 9411:9411 openzipkin/zipkin"
},
"dependencies": {
"express": "^4.14.0",
"zipkin": "^0.6.1",
"zipkin-context-cls": "^0.6.1",
"zipkin-transport-http": "^0.6.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment