Getting started with AWS X-Ray

Mathew Kenny Thomas
Tensult Blogs
Published in
5 min readJun 1, 2018

This Blog has been moved from Medium to blogs.tensult.com. All the latest content will be available there. Subscribe to our newsletter to stay updated.

AWS X-Ray helps developers analyze and debug applications using distributed tracing. Using X-Ray you can pinpoint and understand the root causes of issues, errors, and bottlenecks. With X-Ray, you can identify which part of the application is causing the issue and see the details of the requests being made to the app such as their latency, HTTP response status, number of errors, etc. X-ray provides a visual map of your application’s architecture so that you can quickly see where errors are occurring. X-ray makes it easy to analyze apps running on EC2 or on containers via the EC2 container service. It can also identify the impact of issues on the users of the application. It can visualize the service call graph of your application.

There are two main components of the X-ray. The X-ray SDK and X-ray daemon. X-ray SDK’s available for Java, .NET and Node.js. It enables you to get started quickly without having to manually instruct your application code to log metadata about requests. The X-ray daemon runs on your instances whether it is on-premises or in AWS or even if it’s in the lambda function, and collects metrics that are produced by the SDK. It receives data from the SDK over UDP and acts as a local buffer.

X-ray provides a set of API’s to enable you to send, filter and retrieve trace data. You can do both batch requests and single requests. You can send trace data directly to the service by writing your own SDK’s, for languages not currently supported. You can build native data analysis applications on top of the data collected by X-ray. You can get all those data through various queries. The batch “get API’s” allows you to construct filters and queries on the traces that you are submitting to dive deep on the data. The four main actions of the X-ray API are:

  1. PutTraceSegments — uploads segment documents to AWS X-ray
  2. BatchGetTraces — retrieves a list of traces specified by ID
  3. GetServiceGraph — retrieves a document(JSON) that describes services in your applications and their connections.
  4. GetTraceSummaries — retrieves ID’s and metadata for traces available for a specific time frame using an optional filter.

Now let’s take a look at some of the concepts of X-ray:

  1. Trace: end-to-end data related to a single request across all services
  2. Segments: portions of the trace that corresponds to a single service. Portions of the Trace ID that you are interested to dive deep on.
  3. Sub-segments: Remote call or local compute sections within a service.
  4. Annotations: Business data that can be used to filter traces.
  5. Metadata: Business data that can be used to add to trace but not for filtering the trace.
  6. Errors: Normalised error message and stack trace.
Source: Amazon

Consider the situation where you are pushing data into DynamoDB and it’s not scaling quickly, which is getting you throttled and you want to figure out the requests that are getting throttled. It is very easy to do. You have a Trace ID or capture a whole series of them and you can put in brackets “throttled” on the service DynamoDB or in the name of your table and it will find all of the traces that were throttled. You can associate various metadata with these traces. The trace ID is a 96 bit globally unique ID for a trace (24 hex digits).

Some use cases of X-ray can be listed as:

  1. Understanding your dependencies — When your system is simple, it’s easy to understand your dependencies. But when you have a micro service architecture, understanding your dependencies becomes very hard. This is where AWS X-ray can help you out. Tracing helps you to visualise the reality of your production system. It helps you understand what your system actually looks like. X-ray helps you understand the complexity of a distributed system.
  2. Trouble shooting slow performances — Once you get an alert that something has decreased in performance we can look at the trace of the service that is running slow. X-ray tells us the time each service is taking and gives us the request details. We can look at the trace details and spot the problem. You can fix the bug, deploy and check X-ray again.

X-ray gives us deep insight into our services to investigate when things go wrong. Analysis of the traces allows us to understand detailed information about how services are interacting with each other.

Benefits of X-ray

  1. Review request behaviour — X-ray traces user requests as they travel through your entire application. We are able to get an end-to-end view of how our application is performing as this request aggregates the data generated by various services and resources in your application.
  2. Ready to use with AWS — X-ray works with Amazon EC2, EC2 Container Service (ECS), Lambda and Elastic Beanstalk.
  3. Detect application issues — with X-ray you can obtain insights into how your application is performing and find root causes for any issues. With X-ray’s tracing feature you can find what and where are the issues causing performance dips in your application.
  4. Improve application performance — X-ray helps you identify performance bottlenecks. The service map feature helps you see relationship between resources and services in your application. You can drill down into specific services and paths that are impacting application performance by detecting where high latencies are occurring.

Both New Relic and AWS X-ray have their own benefits and cannot be seen as direct competitors. AWS X-ray is a highly integrated product which is tightly coupled to one platform and supports only a few of the web development languages. On the other hand New Relic is a more of a general solution for application performance and works for cloud based and self deployed environments. It also supports all web development languages. Even though AWS X-ray supports only a few languages we have to keep in mind that it is a recently launched product and that Amazon will continue to develop it’s product. Both products offer a solution that were considered to be very cumbersome before.

Pricing for 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 the free tier, traces recorded cost $5 per 1 million traces recorded ($0.000005 per trace).
  • Beyond the free tier, traces retrieved or scanned cost $0.50 per 1 million traces retrieved or scanned ($0.0000005 per trace).

Pricing for New Relic

New Relic has flexible pricing options to fit your monitoring needs. Your price is based on the size of your instance, the number of instances, and the total time it is running. It has a yearly or a monthly (without a yearly contract the costs are 3x higher) billing cycle. It also has a pro (for organisations with complex environments and/or more advanced monitoring needs) or an essential plan (for organisations needing only the essential APM capabilities, without advanced features and support) available to meet your needs.

--

--