A Brief Introduction to AWS X-Ray

Himansh Kumar
5 min readMay 8, 2020

--

1. How did I come across AWS X-Ray?

As a part of my recent experience, I was able to work with an application whose architecture involved a combination of micro-services. These micro-services made use of third-party APIs. A drawback to using these third-party APIs are not being able to resolve if the origin of the issue is from the third-party API or one of the pre-existing major APIs. During my exploration of tools to help us on the same, I came across AWS X-Ray. This helped us find the exact point at which our application was failing and was able to raise an exception for the un-predicted errors.

In this blog, I will be giving a brief description and benefits of using AWS X-Ray.

2. What is AWS X-Ray?

AWS X-Ray is a service that collects data about requests that your application serves and provides tools you can use to view, filter, and gain insights into that data to identify issues and opportunities for optimization. You can see detailed information not only about request and response but also about the calls that your application makes to downstream AWS resources, third party applications, micro-services, databases, and HTTP Web APIs.

The detailed information about the calls made is shown in the form of traces.

Source: X-Ray Docs

X-Ray SDK sends the JSON segment document to the X-Ray daemon and the X-Ray daemon further sends the data to the X-Ray console. The X-Ray daemon buffers segment in the queue and uploads them to X-Ray in batches.

The SDK helps the application to get started quickly in order to log application metadata without explicitly instructing your application to do so.The SDK supported languages and frameworks:-

  • C#
  • Go
  • Java
  • Node.js
  • Python
  • Ruby

The daemon is installed in the base system.

AWS also provides direct integration with some of the services. The AWS service providing X-Ray integration are as follows:-

  • AWS Lambda
  • Amazon API Gateway
  • Elastic Load Balancing
  • AWS Elastic Beanstalk
  • AWS SNS
  • AWS SQS

You can even integrate your localhost or an on-premise server with AWS X-Ray.

3. Concepts of AWS X-Ray

  1. Segments
  2. Subsegments
  3. Traces
  4. Service Graph
  5. Sampling

3.1 Segments

The compute resources running your application logic send data about their work as segments. A segment provides the following information:-

• The host — hostname, alias or IP address

• The request — method, client address, path, user agent

• The response — status, content

• The work that’s done — start and end times, subsegments

• Issues that occur — errors, faults, and exceptions that occur

3.2 Subsegments

The subsegments provide the more granular timing information and details about the downstream calls that the application makes to SQL database, DynamoDB or an external HTTP API(Third-party applications)

Source: X-RAY Docs

3.3 Traces

AWS X-Ray traces user requests as they travel through your entire application. It aggregates the data generated by the individual services and resources that make up your application, providing you an end-to-end view of how your application is performing.

3.4 Service Graph

X-Ray uses the trace data from AWS resources and APIs to generate a detailed service map. The service graph shows the client, frontend, backend, and the services/API that your backend calls. Users can use the service graph to identify bottlenecks, latencies, and other issues to improve performance and solve issues of your application.

AWS X-Ray receives data from services as segments. X-Ray then groups segments that have a common request into traces. X-Ray processes the traces to generate a service graph that provides a visual representation of your application.

3.5 Sampling

To ensure efficient tracing and provide a representative sample of the requests that your application serves, the X-Ray SDK applies a sampling algorithm to determine which requests get traced.

By default, the X-Ray SDK records the first request each second, and five percent of any additional requests.

4. Advantages of AWS X-Ray

  • It provides architecture with a live architecture diagram.
  • Pinpoints the bottlenecks in the application.
  • It helps to optimize the performance of the application.
  • Helps optimize SQL queries.
  • Enables data-driven architecture decisions.

Use Case of AWS X-Ray

  • It helps in finding out the particular micro-service failing in the application.
  • Helps in finding bottlenecks in the application.
  • Helps in analyzing the SQL query executing time in the application.
  • It helps in analyzing execution time from one micro-service to another.

5. Pricing of AWS X-Ray

Free tier:

  • The first 100,000 traces recorded each month are free.
  • The first 1,000,000 traces retrieved or scanned each month are free.

Additional Charges

  • Beyond free tier, traces recorded cost $5.00 per million traces.
  • Beyond free tier, traces retrieved or scanned cost $5.00 per million traces.

6. Hands-on

Implementation of X-Ray with Django application.

References:-

https://docs.aws.amazon.com/xray/

--

--