UPCOMING EVENT Discover how nOps streamlines your cost optimization at AWS re: Invent - BOOK A MEETING

NEW Featured eBook: AWS Cloud Cost Allocation: The Complete Guide - Download Now

AWS X-Ray is a service that helps developers analyze and debug applications.

It provides an end-to-end view of requests as they travel through your application, showing a map of your application’s underlying components to identify and troubleshoot the root cause of performance issues and errors. It supports various platforms including AWS EC2, Lambda, ECS, and EKS.

AWS X-Ray collects, records, and maps traces to help users analyze issues (image source: AWS)

How does AWS X-Ray work?

AWS X-Ray SDK diagram (image source: AWS)
  1. AWS X-Ray collects data from your application and from AWS services that are integrated with X-Ray. This involves capturing data for both incoming and outbound requests, as well as other significant events within your application. Each trace includes metadata about the requests.
  2. To enable tracing, your application must be instrumented to send this trace data to X-Ray. For many scenarios, this may only require configuration changes. For instance, a Java application can be configured to instrument all incoming HTTP requests and downstream calls to AWS services. AWS provides various SDKs, agents, and tools to facilitate this instrumentation.
  3. Some AWS services, such as AWS Lambda, are pre-integrated with X-Ray. These services can add tracing headers to incoming requests and send trace data to X-Ray. AWS Lambda also automatically runs the X-Ray daemon on its workers, simplifying the use of the X-Ray SDK.
  4. Instead of sending trace data directly to X-Ray, client SDKs send JSON segment documents to the X-Ray daemon, which listens for UDP traffic. This daemon buffers these segments in a queue and uploads them to X-Ray in batches. The daemon is compatible with Linux, Windows, macOS, and is included in AWS Elastic Beanstalk and AWS Lambda environments.
  5. Using the collected trace data from your AWS resources, X-Ray generates a detailed trace map that illustrates the interactions between your client, front-end service, and backend services involved in processing requests and storing data. This trace map helps identify performance bottlenecks, latency issues, and other performance problems to optimize application performance.
X-Ray trace map (image source: AWS)

What are the benefits of AWS X-Ray?

The key benefits of AWS X-Ray include:

Easier Error Tracking / Debugging

Detects and highlights application errors automatically for quicker debugging.

Visualize Architecture with the Service Map

The X-Ray service map or service graph shows the application architecture and how services interact and depend on one another in real time.
Example X-Ray service map for a web API application (image source: AWS)

Better Performance and Latency Reduction

Analyzes and reduces delays in application response times for better performance.
X-Ray provides information about application requests (image source: AWS)

Query Improvement

Identifies inefficient SQL queries and suggests optimizations.

Root Cause Analysis

Simplifies identifying the underlying causes of application performance issues.

How does AWS X-Ray pricing work?

AWS X-Ray pricing is based primarily on the number of traces recorded, retrieved and scanned. A trace represents a request to your application and may include multiple data points such as for calls to other services and database access.

AWS also offers a free tier, which includes 1 million traces recorded and 1 million traces retrieved each month for the first year. Beyond the free tier, pricing is based on the volume of traces processed, with costs varying by region (below is an example from US-East North Virginia).

Sample AWS X-Ray pricing (source: AWS)

AWS X-Ray Key Concepts

In this section, we’ll clarify any key terms you might have questions about.

What are traces in AWS X-Ray?

AWS X-Ray traces user requests as they travel through your entire application, showing the path that the request takes through your application and the relationships between its components. This gives you a full view of how your application is performing. Each trace has a unique trace ID in X-Ray.
AWS X-Ray traces (image source: AWS)

What are Segments and Subsegments in AWS X-ray?

The compute resources running your application logic send data about their work as segments.

Think of segments as the main data units in a trace. Each segment corresponds to a specific service or component your request touches. For example, if a request hits a load balancer, passes through a microservice, and then interacts with a database, each of these components would generate its own segment. Each segment can represent a service, a method call, or an external HTTP request.

Subsegments provide more granular insight than segments. They break down the data further to detail specific operations or internal tasks within a service, such as SQL queries or external API calls.

Segment data for an X-Ray trace in the AWS management console (image source: AWS)

What is an X-Ray Service Graph?

The service graph is a visual representation of the components of your application and how they are interconnected based on the trace data. The service graph helps identify how services interact and where issues might occur in the application workflow.

What are annotations and metadata?

Annotations are key-value pairs that you can use to index traces and filter against them. Metadata are key-value pairs that provide additional context about the trace but are not indexed. Both are used to enrich the trace data and make it more useful for debugging and analysis purposes.

What is the X-Ray daemon?

The X-Ray daemon collects traces and sends them to the X-Ray service for aggregation, analysis, and storage. You can use it to send data to X-Ray, instead of using the APIs directly.

What is sampling?

Sampling in AWS X-Ray is a mechanism to efficiently capture information about the requests your application processes without recording every single request, which can be resource-intensive. You can configure rules to specify which requests to trace and which to ignore, based on criteria such as request type, frequency, and response time.

Sampling rules tell the X-Ray SDK how many requests to record for a set of criteria. By default, the X-Ray SDK records the first request each second, and five percent of any additional requests.

AWS X-Ray FAQ

Here are some frequently asked questions about X-Ray:

Does X-Ray provide an API?

Yes, X-Ray provides APIs. You can use the X-Ray API to easily export trace data to build analysis and visualization applications in addition to those provided by X-Ray.

Which AWS service can I use with X-Ray?

You can use X-Ray with applications running on EC2, ECS, Lambda, Amazon SQS, Amazon SNS and Elastic Beanstalk. In addition, the X-Ray SDK automatically captures metadata for API calls made to AWS services using the AWS SDK with add-ons for MySQL and PostgreSQL drivers.

What coding languages does the X-Ray SDK support?

The X-Ray SDK supports:

  • Go
  • Java
  • js
  • Python
  • .Net
  • Ruby

Get better performance at lower costs with nOps

If you’re looking to optimize your AWS costs, nOps makes it easy and painless for engineers to take action on cloud cost optimization.

The nOps all-in-one cloud platform features include:

Business Contexts: Understand and allocate 100% of your AWS bill down to the container level

Compute Copilot: Intelligent provisioner that helps you save with Spot discounts to reduce On-Demand costs by up to 90%

Commitment management: Automatic life-cycle management of your EC2/RDS/EKS commitments with risk-free guarantee

Storage migration: One-Click EBS volume migration

Rightsizing: Rightsize EC2 instances and Auto Scaling Groups

Resource Scheduling: Automatically schedule and pause idle resources

nOps was recently ranked #1 with five stars in G2’s cloud cost management category, and we optimize $1.5+ billion in cloud spend for our customers.

Join our customers using nOps to understand your cloud costs and leverage automation with complete confidence by booking a demo today!