Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
/ hapi-xray Public archive
forked from moonthug/hapi-xray

AWS X-Ray plugin for HapiJS

Notifications You must be signed in to change notification settings

Short-io/hapi-xray

 
 

Repository files navigation

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

About

AWS X-Ray plugin for HapiJS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%