As XRay currently doesn't support koa, I try to create an instance of the client manually and without a framework-assignment:
import * as XRay from 'aws-xray-sdk';
XRay.setLogger(console);
XRay.config([ XRay.plugins.EC2Plugin, XRay.plugins.ECSPlugin ]);
XRay.enableAutomaticMode();
const segment = new XRay.Segment("root");
XRay.setSegment(segment);
However this snippet results in an error in this line: XRay.setSegment(segment);
Error is:
Error: No context available. ns.run() or ns.bind() must be called first.
Hi, there is a known issue of the incompatibility between Koa and CLS (a core dependency of the X-Ray SDK). The support is in our backlog but we cannot provide a timeline. See more discussion here: https://github.com/aws/aws-xray-sdk-node/issues/4. I'm closing this so we have a central place to trace Koa related issues and progress. Feel free to leave further comments there.
But that wasn't really my issue as I try to use AWSXRay independent from any Server-Framework.
Hi NachtmahrEDM,
You'll need to take a look at the section Developing Custom Solutions using Automatic Mode in our readme.
Since you're building your own segment context, you'll need to setup the namespace as well.
ns.run(function () {
AWSXRay.setSegment(segment);
....
});
Take a look at the Lambda environment code and the Express middleware for additional configuration examples.
However, currently the X-Ray SDK does not support the async/await structure (as seen in the other Koa thread) and context may be lost as mentioned above. We have a task to move to the X-Ray SDK either to cls-hooked or another context propagation framework to work around this.
Hope this helps,
Sandra
Closing. @NachtmahrEDM feel free to open a new one if you need further assistance to get custom solution working.
Most helpful comment
Hi NachtmahrEDM,
You'll need to take a look at the section Developing Custom Solutions using Automatic Mode in our readme.
Since you're building your own segment context, you'll need to setup the namespace as well.
Take a look at the Lambda environment code and the Express middleware for additional configuration examples.
However, currently the X-Ray SDK does not support the async/await structure (as seen in the other Koa thread) and context may be lost as mentioned above. We have a task to move to the X-Ray SDK either to cls-hooked or another context propagation framework to work around this.
Hope this helps,
Sandra