How to implement XRay in NodeJS project?

291 Views Asked by At

I've a nodejs project with Docker and ECS in AWS and i need to implement XRay to get the traces but I couldn't get it to work yet

I installed 'aws-xray-sdk' (npm install aws-xray-sdk), then I added

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

in app.js Then, before the routes I added

app.use(AWSXRay.express.openSegment('Example'));

and after the routes:

app.use(AWSXRay.express.closeSegment());

I hit some endpoints but I can't see any trace or data in xray, maybe do I need to setup something in AWS ? I have a default group in xray. Thanks!

2

There are 2 best solutions below

0
On
0
On

It sounds like you do not have the XRay Daemon running in your ECS environment. This daemon must be used in conjunction with the SDKs to send the trace data to AWS XRay service from the SDKs. The daemon listens for the trace data traffic on UDP port 2000. Read more about the daemon here: https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon.html

See how to run the XRay Daemon on ECS via Docker here: https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon-ecs.html