0.1.5 • Published 3 years ago

@w3d3/express-opentracing v0.1.5

Weekly downloads
66
License
Apache-2.0
Repository
github
Last release
3 years ago

express-opentracing

Middleware for express to enable opentracing. Supports any opentracing tracer compatible with version 0.11.0 of the opentracing javascript library.

Install

npm install --save express-opentracing

Usage

E.g., using LightStep as your tracer:

import * as express from "express";
import middleware from "express-opentracing";
import * as LightStep from "lightstep-tracer";

const lsTracer = LightStep.tracer({
  access_token   : 'foo',
  component_name : 'bar',
});

const app = express();
app.use(middleware({tracer: lsTracer}));

To trace specific HTTP calls, or to exclude certain calls (e.g. hosted static content), modify app.use(middleware()) above:

app.use((req, res, next) => {
  // exclude paths that start with '/css' or '/js'
  if (req.path.startsWith("/css") || req.path.startsWith('/js')) {
    return next()
  }
  // trace calls
  middleware({tracer: tracer})(req, res, next);
});

To use a span (e.g for logging) access the req.span object from your handler:

app.use((req, res, next) => {
  req.span.log({ event: 'handler_triggered' })
})

Options

The middleware function takes in an options object as its only argument.

const options = {
  tracer: [Tracer], // Defaults to the opentracing no-op tracer.
}
0.1.4

3 years ago

0.1.5

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago