AWS, Cloud Computing

4 Mins Read

AWS X-RAY tracing for Flask Application

Voiced by Amazon Polly

Introduction

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.

intro

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

intro2

Customized Cloud Solutions to Drive your Business Success

  • Cloud Migration
  • Devops
  • AIML & IoT
Know More

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.

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

Step4

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

Step4b

  • 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’

Step4c

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

Step5

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.

Step6

Conclusion

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 a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.

CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training PartnerAWS Migration PartnerAWS Data and Analytics PartnerAWS DevOps Competency PartnerAWS GenAI Competency PartnerAmazon QuickSight Service Delivery PartnerAmazon EKS Service Delivery Partner AWS Microsoft Workload PartnersAmazon EC2 Service Delivery PartnerAmazon ECS Service Delivery PartnerAWS Glue Service Delivery PartnerAmazon Redshift Service Delivery PartnerAWS Control Tower Service Delivery PartnerAWS WAF Service Delivery PartnerAmazon CloudFront Service Delivery PartnerAmazon OpenSearch Service Delivery PartnerAWS DMS Service Delivery PartnerAWS Systems Manager Service Delivery PartnerAmazon RDS Service Delivery PartnerAWS CloudFormation Service Delivery PartnerAWS ConfigAmazon EMR and many more.

FAQs

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.

Share

Comments

    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!