aws / aws-xray-sdk-node

The official AWS X-Ray SDK for Node.js.
Apache License 2.0
271 stars 155 forks source link

Error: No context available. ns.run() or ns.bind() must be called first. NestJS #454

Closed akashdeep-sharma closed 3 years ago

akashdeep-sharma commented 3 years ago

I am getting No context available at setSegement(). I am using Nest Js framework

const AWSXRay = require('aws-xray-sdk');
const AWS = AWSXRay.captureAWS(require('aws-sdk'));
AWSXRay.captureHTTPsGlobal(require('https'));
 seg = new AWSXRay.Segment('aws-Xray');
    AWSXRay.setSegment(seg);
    seg.addAnnotation('functionName', 'mainFunction');
    console.log(seg);
willarmiros commented 3 years ago

As the error message indicates, you must call setSegment within a ns.run() or ns.bind() closure. For example see: https://github.com/aws/aws-xray-sdk-node/tree/master/packages/core#developing-custom-solutions-without-middleware