Skip to content

samgiles/zipkin-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zipkin express middleware

API

The zipkin-middleware object can be created with an options object that accepts the following options:

Key Description Default
'scribeHost' The host the scribe daemon is running on 'localhost'
'scribePort' The port the scribe daemon is listening on 1463
'scribeCategory' The name of the category to send the Zipkin traces to 'zipkin'
'serviceName' The name of the service to identify it in Zipkin traces 'default-express-app'

For example:

var zipkinMiddleware = new ZipkinMiddleware({
	scribeHost: '10.0.0.3',
	scribePort: 1234,
	scribeCategory: 'my-custom-category',
	serviceName: "my-service"
});

Using the middleware

The created middleware object needs to be installed on a route using the install method, for example:

var zipkinMiddleware = new ZipkinMiddleware();
app.use(zipkinMiddleware.install());

Additionally the middleware must be initialised before starting the HTTP server using the initialize, async method.

var zipkinMiddleware = new ZipkinMiddleware();
zipkinMiddleware.initialize(function(error, ready) {
	if (error) { throw error; }
	app.listen(myAppsPort, bindAddress);
});

Basic Usage

var express = require('express');
var app = express();

var ZipkinMiddleware = require('zipkin-middleware');

// Create a new Middleware object
var zipkinMiddleware = new ZipkinMiddleware({
	serviceName: "my-service"
});

// Install the middleware
app.use(zipkinMiddleware.install());

// Create routes etc. as normal
app.get('/', function(request, response) {
	request.addTraceAnnotation('some', 'extra data to attach to the trace');

	response.send("Hello World");
});

// Because the middleware needs to asynchronously connect to the scribe daemon
// we need to initialise it for the first time before serving requests in
// order to capture all requests.
zipkinMiddleware.initialise(function(error, ready) {
	if (error) {
		throw error;
	}

	// Once connected, start the http server
	app.listen(8080, 'localhost');
});

License

MIT

About

Zipkin middleware for express applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published