3.0.6 • Published 4 years ago

hapi-xray v3.0.6

Weekly downloads
118
License
MIT
Repository
github
Last release
4 years ago

Obsolete

This package has now been merged into the official aws-xray-sdk-node

The new package is available as aws-xray-sdk-hapi

hapi-xray

Known Vulnerabilities

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

Version 3.0 Breaking Changes

As of version 3.0, the plugin now works in "automatic mode" and uses this mode by default in order to establish parity with the other X-Ray helper libraries (express/restify).

Manual mode can be enabled by setting automaticMode to false when specifying options.

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]
  }
});

In automatic mode, you can access the X-Ray segment at any time via the AWSXRay SDK:

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

const segment = AWSXRay.getSegment();
segment.addAnnotation('hitController', 'true');

In manual mode, you can access the current X-Ray segment from the request object:

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

Options

  • segmentName Segment name to use in place of default segment name generator
  • automaticMode Specifies that X-Ray automatic mode is in use (default true)
  • 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 peer dependency
  • captureHTTP Enables AWS X-Ray to capture all http calls
  • capturePromises Enables AWS X-Ray to capture all promises
  • logger Bind AWS X-Ray to compatible logging interface ({ trace, debug, info })

Thanks

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

Contributors

3.0.6

4 years ago

3.0.5

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago