JSPM

  • Created
  • Published
  • Downloads 349077
  • Score
    100M100P100Q191233F
  • License Apache-2.0

AWS X-Ray Middleware for Express (Javascript)

Package Exports

  • aws-xray-sdk-express

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (aws-xray-sdk-express) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Requirements

AWS X-Ray SDK Core (aws-xray-sdk-core) Express 4.14.0 or greater

AWS X-Ray and Express

AWS X-Ray Express package automatically records information for incoming and outgoing requests and responses, via the middleware functions in this package.

The AWS X-Ray SDK Core has two modes - 'manual' and 'automatic'. Automatic mode uses the Continuation Local Storage package (CLS) and automatically keeps track of the current segment and subsegment. This is the default mode. Manual mode requires you pass around the segment reference.

In automatic mode, you can get the current sub/segment at any time: var segment = AWSXRay.getSegment();

In manual mode, you can get the base segment off the request object: var segment = req.segment;

Sampling rates on routes

Sampling rates are determined by the AWS X-Ray SDK Core package, using the default provided sampling file, or by overriding this with a custom sampling file. For more information on sampling, please see the aws-xray-sdk-core README.

Dynamic and fixed naming modes

A default segment name is required to be set when using middleware. If it is not set, an error will be thrown. This value can be overridden via the AWS_XRAY_TRACING_NAME environment variable.

app.use(xrayExpress.openSegment('defaultName'));

The AWS X-Ray SDK Core defaults to a fixed naming mode. This means that each time the middleware creates a new segment for an incoming request, the name of that segment is set to the default name. In dynamic mode, the segment name can vary between the host header of the request or the default name. For more information on naming modes, please see the aws-xray-sdk-core README.

Automatic mode examples

var AWSXRay = require('aws-xray-sdk-core');
var xrayExpress = require('aws-xray-sdk-express');
var app = express();

//...

app.use(xrayExpress.openSegment('defaultName'));

app.get('/', function (req, res) {
  var segment = AWSXRay.getSegment();

  //...

  res.render('index');
});

app.use(xrayExpress.closeSegment());

Manual mode examples

var AWSXRay = require('aws-xray-sdk-core');
var xrayExpress = require('aws-xray-sdk-express');
var app = express();

//...

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

app.use(xrayExpress.openSegment('defaultName'));               //required at the start of your routes

app.get('/', function (req, res) {
  var segment = req.segment;

  //...

  res.render('index');
});

app.use(xrayExpress.closeSegment());   //required at the end of your routes / first in error handling routes