Notable Pottery Manufacturer

    @johnytiago/express-opentracing
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.1 • Public • Published

    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 = new 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.
    }

    Install

    npm i @johnytiago/express-opentracing

    DownloadsWeekly Downloads

    3

    Version

    0.1.1

    License

    Apache-2.0

    Unpacked Size

    22.5 kB

    Total Files

    12

    Last publish

    Collaborators

    • johnytiago