{"id":6572,"date":"2024-01-19T09:00:00","date_gmt":"2024-01-19T08:00:00","guid":{"rendered":"https:\/\/blog.besharp.it\/?p=6572"},"modified":"2024-02-02T11:07:16","modified_gmt":"2024-02-02T10:07:16","slug":"hands-on-instrumenting-aws-lambda-with-aws-x-ray","status":"publish","type":"post","link":"https:\/\/blog.besharp.it\/hands-on-instrumenting-aws-lambda-with-aws-x-ray\/","title":{"rendered":"Hands-on: Instrumenting AWS Lambda with AWS X-Ray"},"content":{"rendered":"\n
Working with microservices<\/strong> has many advantages, but it also has some flaws. One of them undoubtedly is debugging and logging the whole application.\u00a0<\/p>\n\n\n\n Every microservice may produce logs in a different place, and jumping from one to another while debugging could be time-consuming. <\/p>\n\n\n\n Moreover, knowing what microservices are part of an application and finding bottlenecks or points of failure can be tricky, especially with massive and poorly documented applications.<\/p>\n\n\n\n X-Ray solves both problems<\/strong>, providing a centralized point to access your application logs and consult a map representing your microservices, resources, and how they communicate.<\/p>\n\n\n\n X-Ray is a service that allows you to gather data from applications you want to monitor so that you can analyze them to find possible issues or ways to improve your application performance. Sending trace data for incoming and outbound requests and other events lets you see which AWS resources, microservices, and web APIs are used.<\/p>\n\n\n\n This process is called \u201cInstrumentation\u201d<\/strong>.<\/p>\n\n\n\n There are different types of instrumentations:<\/p>\n\n\n\n Many AWS services provide X-Ray integration, such as AWS Lambda, Amazon API Gateway, Amazon Simple Notification Service, or Amazon Simple Queue Service.<\/p>\n\n\n\n AWS services integration with X-Ray can be split into:<\/p>\n\n\n\n The data sent by your application services are called segments. <\/strong>Segments contain different information based on the nature of the request. For instance, an HTTP request will contain information such as the URL, the method, and the response code.<\/p>\n\n\n\n A segment can be split into subsegments<\/strong> to provide more information about all the actors involved in the work. The segment of your application can be split into different subsegments for each function it runs to know the functions’ order and duration. Subsegments are also used by X-Ray to create \u201cinferred segments\u201d for services that don\u2019t support X-Ray, such as DynamoDB. This allows X-Ray to show them in the trace map.<\/strong> The trace map shows all the services involved and can be used to analyze the application workflow. The trace map is built using traces.<\/strong> A trace is a collection of all segments generated by a single request to your application.<\/p>\n\n\n\n <\/p>\n\n\nX-Ray Introduction<\/h2>\n\n\n\n
\n
\n
X-Ray Fundamentals<\/h2>\n\n\n\n