3.6.0 • Published 1 month ago

aws-xray-sdk-koa2 v3.6.0

Weekly downloads
203
License
Apache-2.0
Repository
github
Last release
1 month ago

Requirements

AWS X-Ray SDK Core (aws-xray-sdk-core) Koa 2.x or greater

AWS X-Ray and Koa

The AWS X-Ray Koa package automatically records information for incoming and outgoing requests and responses, via the middleware functions 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/subsegment at any time: var segment = AWSXRay.getSegment();

In manual mode, you can get the base segment off of the context object: var segment = ctx.segment;

Middleware Usage

The Koa X-Ray SDK provides one middlewares: xrayKoa.openSegment(<name>). This middleware will wrap all of the defined routes that you'd like to trace. In automatic mode, the openSegment middleware must be the last middleware added before defining routes, otherwise issues with the cls-hooked context may occur.

Automatic mode examples

var AWSXRay = require('aws-xray-sdk-core');
var xrayKoa = require('aws-xray-sdk-koa2');
var app = new Koa();

//...

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

router.get('/myRoute', (ctx) => {
    const segment = AWSXRay.getSegment();
    //Do whatever 
});

Manual mode examples

var AWSXRay = require('aws-xray-sdk-core');
var xrayKoa = require('aws-xray-sdk-koa2');
var app = new Koa();

//...

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

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

router.get('/myRoute', (ctx) => {
    const segment = ctx.segment;
    //Do whatever 
});
3.6.0

1 month ago

3.5.4

2 months ago

3.5.3

6 months ago

3.5.2

7 months ago

3.5.1

9 months ago

3.5.0

1 year 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

0.0.1-security

4 years ago