If you are a bit confused with the AWS X-Ray service, here is a visual explanation on how AWS X-Ray works.
Quick service description
AWS X-Ray is a distributed tracing tool.
It helps you analyze and debug production, distributed applications which is handy in the case of microservices architectures (where lots of microservices need to communicate together over https).
By using AWS X-Ray you can get a neat “service map” to troubleshoot and understand the path of the request, the response codes for each microservice, the average response time, etc …
One thing worth noting is that X-Ray integrates with some AWS services (API Gateway, Lambda, …) but you can also use X-Ray in you application code (Node.js, etc …).
Let’s go in the “Traces” section of X-Ray:
Here I can access the “traces”:
If I click on the first one (status OK 200), I’ll get the “segments” making up this “trace” and the details for each segment (quite useful to troubleshoot).
You can also use the X-Ray SDK to create subsegments (take a look, I’ve created a “Wait 1 second” subsegment inside the code of my Lambda before making HTTP call to an external API: pokeapi.co)
Here is what the code inside my Node.js Lambda function looks like to create the sub-segment:
How does it work ?
Here are 2 illustrations that might help you to understand how AWS X-Ray works:
The end
I hope this story helped you