3.6.0 • Published 3 days ago

aws-xray-sdk-restify v3.6.0

Weekly downloads
197
License
Apache-2.0
Repository
github
Last release
3 days ago

Requirements

  • AWS X-Ray SDK Core (aws-xray-sdk-core)
  • Restify 4.3.0 or greater

AWS X-Ray and Restify

The AWS X-Ray Restify package automatically records information for incoming and outgoing requests and responses, via the 'enable' function in this package. To configure sampling, dynamic naming, and more see the set up section.

The AWS X-Ray SDK Core has two modes - manual and automatic. Automatic mode uses the cls-hooked package and automatically tracks the current segment and subsegment. This is the default mode. Manual mode requires that you pass around the segment reference.

In automatic mode, you can get the current segment or subsegment at any time:

var segment = AWSXRay.getSegment();

In manual mode, you can get the base segment off of the request object:

var segment = req.segment;

//If the restify context plugin is being used, it is placed under 'XRaySegment'
var segment = req.get('XRaySegment');

Middleware usage

The X-Ray SDK provides a single Restify middleware: AWSXRayRestify.enable(<server>, <defaultName>). This must be added as the last middleware before defining all routes you'd like to have traced, otherwise issues with the cls-hooked context may occur. Error capturing will be done automatically.

Automatic mode examples

For more automatic mode examples, see the example code.

var AWSXRayRestify = require('aws-xray-sdk-restify');
var restify = require('restify');
var server = restify.createServer();

//...

AWSXRayRestify.enable(server, 'defaultName');

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

    //...

    res.send('hello');
});

//Error capturing is attached to the server's uncaughtException and after events (for both handled and unhandled errors)

Manual mode examples

For more manual mode examples, see manual mode examples. The X-Ray SDK can be used identically inside Restify routes. Note that you don't have to manually start or close the segments since that is handled by the X-Ray middleware.

var AWSXRayRestify = require('aws-xray-sdk-restify');
var restify = require('restify');
var server = restify.createServer();

//...

AWSXRayRestify.enable(server, 'defaultName');          //Required at the start of your routes

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

//...

res.send('hello');
});

//Error capturing is attached to the server's uncaughtException and after events (for both handled and unhandled errors)
3.6.0

3 days ago

3.5.4

1 month ago

3.5.3

5 months ago

3.5.2

6 months ago

3.5.1

8 months ago

3.5.0

12 months ago

3.4.1

1 year ago

3.4.0

1 year ago

3.3.8

2 years ago

3.3.7

2 years ago

3.3.6

2 years ago

3.3.5

2 years ago

3.3.4

2 years ago

3.3.3

3 years ago

3.3.2

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

3.0.0-alpha.2

4 years ago

3.0.0-alpha.1

4 years ago

1.7.0-beta

4 years ago

1.6.0-beta

4 years ago

1.5.6-beta

5 years ago

1.5.5-beta

5 years ago

1.5.4-beta

5 years ago

1.5.3-beta

5 years ago

1.5.2-beta

5 years ago

1.5.1-beta

5 years ago

1.5.0-beta

5 years ago

1.4.0-beta

5 years ago

1.3.0-beta

5 years ago

1.2.1-beta

5 years ago

1.2.0-beta

6 years ago

1.1.0-beta

6 years ago

1.0.4-beta

6 years ago

1.0.3-beta

6 years ago

1.0.2-beta

6 years ago

1.0.1-beta

6 years ago

1.0.0-beta

7 years ago