Giter Site home page Giter Site logo

hapi-xray's Introduction

hapi-xray

A HapiJS plugin to log requests and subsegments through AWSXray.

Setup

At the moment, the plugin relies on the AWS credentials being set before being registered, or it will pull them from ~/.aws/credentials as per the SDK default.

It basically works a lot like the Official Express version, however you use the HapiJS syntax to register the plugin (as opposed to app.use(AWSXRay.express.openSegment('defaultName')))

For more details on using X-Ray, see the docs

It currently only works in 'manual' mode, setting the current 'segment' on each request.

Usage

Simply register as a normal plugin

const AWSXRay = require('aws-xray-sdk');

await server.register({
  plugin: require('hapi-xray'),
  options: {
    captureAWS: true,
    plugins: [AWSXRay.plugins.ECSPlugin]
  }
});

You can then use the X-Ray SDK as normal in your routes taking the current segment from the request

server.route({
  method: 'GET',
  path: '/items',
  handler: async (request, h) => {
    const segment = request.segment;
    segment.addAnnotation('hitController', 'true');
    
    return {};
  }
});

Options

  • plugins An array of AWS plugins to use (i.e. [AWSXRay.plugins.EC2Plugin])
  • captureAWS Enables AWS X-Ray to capture AWS calls
    • This requires having aws-sdk installed as a dependency
  • setLogger Bind AWS X-Ray to a compatible logging interface ({ trace, debug, info })

Thanks

Based on the hard work @AWS X-Ray Express Middleware

Built with ♥︎ for Progressive Content

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.