Skip to content

Instantly share code, notes, and snippets.

@byteshiva
Created September 29, 2016 12:24
Show Gist options
  • Save byteshiva/f717fb364ef0dd3f2c09ebb61da90a6d to your computer and use it in GitHub Desktop.
Save byteshiva/f717fb364ef0dd3f2c09ebb61da90a6d to your computer and use it in GitHub Desktop.
Es5 working example for zipkins
{
"name": "sample zipkin cliet app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Siva",
"license": "MIT",
"dependencies": {
"express": "^4.14.0",
"express-http-proxy": "^0.7.4",
"zipkin": "git+https://github.com/byteshiva/zipkin.git",
"zipkin-instrumentation-express": "git+http://github.com/byteshiva/zipkin-instrumentation-express.git",
"zipkin-transport-http": "git+https://github.com/byteshiva/zipkin-transport-http.git"
}
}
This example has made to work in node version v0.10.35
#run local server using docker.
docker run -d -p 9411:9411 openzipkin/zipkin
open browser to see changes reflected on zipkin server.
http://localhost:9411/
'use strict';
var _require = require('zipkin');
var Tracer = _require.Tracer;
var BatchRecorder = _require.BatchRecorder;
var ExplicitContext = _require.ExplicitContext;
var _require2 = require('zipkin-transport-http');
var HttpLogger = _require2.HttpLogger;
var zipkinBaseUrl = 'http://localhost:9411';
var recorder = new BatchRecorder({
logger: new HttpLogger({
endpoint: zipkinBaseUrl + '/api/v1/spans'
})
});
var ctxImpl = new ExplicitContext();
var tracer = new Tracer({ ctxImpl: ctxImpl, recorder: recorder });
var express = require('express');
var proxy = require('express-http-proxy');
var zipkinMiddleware = require('zipkin-instrumentation-express').expressMiddleware;
var app = express();
app.use(express.static('public'));
// Add the Zipkin middleware
app.use(zipkinMiddleware({
tracer: tracer,
serviceName: 'server' // name of this application
}));
// Serve the bundled browser.js
app.get('/', function (req, res) {
res.send('<html><body><script src="/bundle.js"></script></body></html>');
});
// Mount zipkin's POST endpoint to /zipkin for browsers to use
// In real life, you can re-use your existing auth api when proxying
app.use('/zipkin', proxy(zipkinBaseUrl, {
forwardPath: function forwardPath() {
return '/api/v1/spans';
}
}));
// Actual http call that will end up in the trace
app.get('/api', function (req, res) {
res.send('Hello World!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment