hapi-xray v3.0.6
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
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
segmentNameSegment name to use in place of default segment name generatorautomaticModeSpecifies that X-Ray automatic mode is in use (default true)pluginsAn array of AWS plugins to use (i.e.[AWSXRay.plugins.EC2Plugin])captureAWSEnables AWS X-Ray to capture AWS calls. This requires havingaws-sdkinstalled as a peer dependencycaptureHTTPEnables AWS X-Ray to capture all http callscapturePromisesEnables AWS X-Ray to capture all promisesloggerBind AWS X-Ray to compatible logging interface({ trace, debug, info })
Thanks
Based on the hard work @AWS X-Ray Express Middleware
Contributors
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago