AWS, Cloud Computing

4 Mins Read

AWS X-RAY tracing for Flask Application


AWS X-Ray is a service that gathers information about the requests that an application serves and offers tools for viewing, filtering, and gaining insights into that information to spot problems and chances for improvement.

It is a service that aids in the analysis and debugging of distributed applications for developers. Customers who employ cloud-hosted apps or applications running on their workstations for development use X-Ray to track application traces, including the effectiveness of calls to other downstream components or services.


Applications created in Node.js, Java, Go, C#.NET, and Python can be traced using AWS X-Ray.


End-to-End tracing

AWS X-Ray offers an end-to-end, cross-service perspective of requests made to an application. Combining the information obtained from application services into one object known as a trace provides an application-centric perspective of requests going through the application. To identify the specific service or application tier or tiers where problems are occurring, one can utilize this trace to track the journey of a single request.

  • Cloud Migration
  • Devops
  • AIML & IoT
Know More

Request Sampling

Applications that are in production or that are still being developed are the ideal candidates for setting the trace sampling rate. Requests are continuously tracked by X-Ray, which maintains a sample of them for analysis. This avoids the expense of maintaining and managing an excessive quantity of data volume while providing the right amount of data to make analysis meaningful.

AWS X-Ray SDK for Python

A collection of libraries that can be used to create and transmit traces to X-Ray using the X-Ray daemon.

Download the SDK with pip.

X-Ray daemon

The AWS X-Ray daemon is a piece of software that listens on UDP port 2000 by default for traffic, collects raw segment data, and sends it to the AWS X-Ray API. For data transmitted by the AWS X-Ray SDKs to reach the X-Ray service, the daemon needs to be running in conjunction with the SDKs. Segments created when a service receives an upstream request are forwarded by the X-Ray Daemon. The trace data is sent to the service by an external process that is run in an instance.

Steps to Install X-Ray daemon

Step 1 – 

Step 2 – Create an IAM role called “AWSXRayDaemonWriteAccess” with write permissions and some read permissions to facilitate the use of sampling rules to deploy the application in AWS.

  • The X-Ray SDK for Python creates a segment for each sampled request when you add the middleware to your application and specify a segment name. Timing, method, and HTTP request disposition are all included in this part. This segment’s subsegments are created by further instrumentation.
  • To instrument incoming HTTP requests, the X-Ray SDK for Python supports middleware called a flask. Setting up a segment name on the xray recorder is the first step in instrumenting flask application. Then, modify the code of the Flask application using the XRayMiddleware function.

Step 3 – Add the following configuration to the main page of flask your application

Step 4 – For dependency management add SDK in requirement.txt

  • aws-xray-sdk==2.4.2
  • run requirement.txt file using pip command ‘pip install -r requirements.txt


  • Run the python application using the below command
  • python3 by sending the request to the application
  • Send requests to your application for generating traces


  • If the configurations are right then the X-Ray daemon will be sending the traces and logs can be checked using ‘tail -f /var/log/xray/xray.log’


Step 5 – After launching an application, can see the service map in the X-Ray console in AWS


Step 6 – Click on any node in the graph to view the traces behind it which is used to find traces by URL, response code, or other information from the summary of traces. This enables us to examine every action occurring within your applications.



Hence the service map in X-Ray depicts the connection between the services in an application as well as aggregated metrics for each service, such as average latency and failure rates. can perform call detections across availability zones or regions, build dependency trees, and more.

Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.

  • Cloud Training
  • Customized Training
  • Experiential Learning
Read More

About CloudThat

CloudThat is also the official AWS (Amazon Web Services) Advanced Consulting Partner and Training partner and Microsoft gold partner, helping people develop knowledge of the cloud and help their businesses aim for higher goals using best in industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.

Drop a query if you have any questions regarding AWS X-Ray Tracing and I will get back to you quickly.

To get started, go through our Consultancy page and Managed Services Package that is CloudThat’s offerings.


1. How long does it require for an X-Ray to make trace data available?

ANS: – Usually, the service receives trace data supplied to X-Ray and makes it accessible for retrieval and filtering within 30 seconds of receiving it.

2. Which kinds of applications work with X-Ray?

ANS: – A web application’s HTTP requests or asynchronous events that use Amazon SQS queues can be traced using X-Ray.

WRITTEN BY Abhilasha D

Abhilasha D is a Research Associate-DevOps at CloudThat. She is focused on gaining knowledge of Cloud environment and DevOps tools. She has keen interest in learning and researching on emerging technologies.



    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!