@bookmate/zipkin-express-helpers

0.0.1 • Public • Published

zipkin-express-helpers

Instruments for adding zipkin headers to an Express request object and for reading them back.

Installation

npm install --save @bookmate/zipkin-express-helpers

Usage

If all you need is just to add zipkin headers to requests in Express (e.g. if you are using Express as a proxy), the most convenient way is to use a middleware:

const express = require('express');
const { createZipkinExpressMiddleware } = require('@bookmate/zipkin-express-helpers');

const localServiceName = 'name of this application';

const app = express();

app.use(createZipkinExpressMiddleware({localServiceName}));

For more fine-grained control, you may want to use ZipkinRequestDecorator (which is used in the middleware):

const express = require('express');
const { ZipkinRequestDecorator } = require('@bookmate/zipkin-express-helpers');

const localServiceName = 'name of this application';
const zipkinRequestDecorator = new ZipkinRequestDecorator({ localServiceName });

const customMiddleware = (req, res, next) => {
  zipkinRequestDecorator.addZipkinHeadersToRequest(req);
  // some custom logic
  next();
}

const app = express();

app.use(customMiddleware);

To read zipkin headers from a request, use readZipkinHeadersFromRequest function:

const { readZipkinHeadersFromRequest } = require('@bookmate/zipkin-express-helpers');

function myFunc(req) {
  const zipkinHeaders = readZipkinHeadersFromRequest(req);
  // do something with the headers
}

Readme

Keywords

none

Package Sidebar

Install

npm i @bookmate/zipkin-express-helpers

Weekly Downloads

1

Version

0.0.1

License

ISC

Unpacked Size

6.46 kB

Total Files

7

Last publish

Collaborators

  • andorn
  • bookmate-npm