Tracing serverless application with AWS X-Ray

Tracing serverless application with AWS X-RayKamil PiotrowskiBlockedUnblockFollowFollowingDec 26What is AWS X-ray?AWS X-Ray is a service that records and visualize requests made by your application..It can be used to analyze, monitor and debug distributed applications based on the AWS Lambdas or microservices architecture..With AWS X-Ray you can f.ex.:Keep track of every request made to other AWS services,Discover issues with an application performanceVisualize the path of a single request through the entire application,Detect problems with application permissions.AWS X-Ray supports many computing services such as EC2, ECS, Elastic Bean Stack, AWS Lambda and runtimes..In this article, I will focus on the serverless applications built with AWS Lambdas based on the Golang 1.X runtime.Segments and subsegmentsAWS X-Ray receives information about requests made by your application in the objects named segments..Every segment may contain multiple subsegments which give you a more detailed view of the operations made by the application..Segments with the same Trace-ID are grouped into the single trace and visualized as a service graph..The Trace-ID is generated by the first service in the request and propagated to the other services by adding the X-Amzn-Trace-Id header.Service GraphEvery trace is visualized as a graph containing nodes that represent different AWS services or requests..Every node has its status presented with a different color:Green – SuccessOrange – Error (4XX Response)Red – Fault (5XX Response)Purple – Throttled request (429 Response)How to use it?ConfigurationEnabling AWS X-Ray for AWS Lambda is really simple..You just need to enable active tracing in the AWS console:or if you use cloud-formation to deploy your Lambda, you need to add the following parameter:Properties: TracingConfig: Mode: ActiveYou also need to allow your Lambda to send X-Ray segments by adding at least the following permissions to it’s IAM policy:- “xray:PutTraceSegments”- “xray:PutTelemetryRecords”These two changes are enough for your Lambda to start sending X-ray segment containing information that Lambda has been invoked..However, any other request won’t be recorded..To achieve that you need to install xray-sdk library and make few changes in your function code..The proper library for golang runtime is github.com/aws/aws-xray-sdk-go.. More details

Leave a Reply