Socket
Socket
Sign inDemoInstall

koa-xray

Package Overview
Dependencies
56
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    koa-xray

AWS X-Ray Middleware for koa (Javascript)


Version published
Weekly downloads
13
increased by18.18%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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.

The AWS X-Ray SDK Core has two modes - manual and automatic. Automatic mode uses the Continuation Local Storage package (CLS) 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 request object: var segment = req.segment;

Sampling rates on routes

Sampling rates are determined by the aws-xray-sdk-core package, using the default sampling file that is provided, or by overriding this with a custom sampling file. For more information on sampling, see aws-xray-sdk-core README.

Dynamic and fixed naming modes

The SDK requires that a default segment name is set when using middleware. If it isn't set, an error is thrown. You can override this value via the AWS_XRAY_TRACING_NAME environment variable.

app.use(xrayKoa.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 about naming modes, see the aws-xray-sdk-core README.

Automatic mode examples

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

//...

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

Manual mode examples

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

//...

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

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

router.get('/health', (ctx) => {
    const segment = ctx.segment;
    //Do whatever 
   healthHandlers.performAvailableHealthCheck({ ctx }))
}

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

      //...

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

Keywords

FAQs

Last updated on 04 Jun 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc