AWS X-Ray

AWS X-Ray

  • AWS X-Ray helps developers analyze and debug production, distributed applications for e.g. built using a microservices lambda architecture
  • provides an end-to-end view of requests as they travel through the application, and shows a map of the application’s underlying components.
  • helps to understand how the application and its underlying services are performing to identify and troubleshoot the root cause of performance issues and errors.
  • can help analyze applications in development and in production, from simple three-tier applications to complex microservices applications consisting of thousands of services.
  • can be used with distributed applications of any size to trace and debug both synchronous requests and asynchronous events.
  • can be used to track requests flowing through applications or services across multiple regions. Data is stored locally in the processed region and customers can build a solution over it to combine the data.
  • makes the Trace data available for retrieval and filtering within 30 seconds of it being received by the service.
  • stores trace data for the last 30 days.
  • encrypts traces and related data at rest and supports encryption in transit.
  • Integration
    • X-Ray integrates with applications running on EC2, ECS, Lambda, and Elastic Beanstalk.
    • X-Ray SDK automatically captures metadata for API calls made to AWS services using the AWS SDK
    • X-Ray SDK provides add-ons for MySQL and PostgreSQL drivers.
    • For Elastic Beanstalk, include the language-specific libraries in the application code.
    • Applications running on other AWS services, such as EC2 or ECS, install the X-Ray agent and instrument the application code

X-Ray Architecture

X-Ray Core Concepts

  • Segment
    • A Segment encapsulates all the data points for a single component of the distributed application for e.g. authorization component.
    • A segment provides the resource’s name, details about the request, and details about the work done.
    • Segments include system-defined and user-defined data in the form of annotations and are composed of one or more sub-segments that represent remote calls made from the service.  for e.g. database call and its result within the overall request/response
  • Subsegments
    • A segment can break down the data about the work done into subsegments.
    • Subsegments provide more granular timing information and details about downstream calls that the application made to fulfill the original request.
    • A subsegment can contain additional details about a call to an AWS service, an external HTTP API, or an SQL database.
    • Arbitrary subsegments can be defined to instrument specific functions or lines of code in the application.
  • Trace
    • Trace collects all the segments generated by a single request.
    • Trace is a set of data points that share the same trace ID.
    • Trace helps track the request, which is assigned a unique trace id, while it navigates through services
    • Piece of information relayed by each service in the application to X-Ray is a segment, and a trace is a collection of segments.
  • Filter Expressions
    • Filter expressions can be used to find traces related to specific paths or users.
  • Annotations and Metadata

    • Annotations are simple key-value pairs that are indexed for use with filter expressions.
    • Metadata are key-value pairs with values of any type, including objects and lists, but that is not indexed.
    • An Annotation is system-defined or user-defined data
      • System-defined annotations include data added to the segment by AWS services
      • User-defined annotations are metadata added to a segment by a developer
    • Annotations and metadata are aggregated at the trace level and can be added to any segment or subsegment.
    • Annotation and metadata are associated with a segment and a segment can contain multiple annotations.
  • Errors, Faults, and Exceptions

    • X-Ray errors are system annotations associated with a segment for a call that results in an error response.
    • Error includes the error message, stack trace, and any additional information for e.g, version to associate the error with a source file.
    • Error – Client errors (400 series errors)
    • Fault – Server faults (500 series errors)
    • Throttle – Throttling errors (429 Too Many Requests)
  • Sampling
    • X-Ray collects data for a significant number of requests, instead of each request sent to an application, for performant and cost-effectiveness
    • X-Ray should not be used as an audit or compliance tool because it does not guarantee data completeness.
    • By default, the X-Ray SDK records the first request each second, and five percent of any additional requests.

X-Ray Daemon

  • X-Ray daemon is a software application that listens for traffic on UDP port 2000, gathers raw segment data, and relays it to the AWS X-Ray API.
  • Daemon works in conjunction with the AWS X-Ray SDKs and must be running so that data sent by the SDKs can reach the X-Ray service.

X-Ray API

  • X-Ray API provides access to all X-Ray functionality through the AWS SDK, AWS Command Line Interface, or directly over HTTPS.

X-Ray with VPC Endpoints

  • X-Ray can be configured to use an Interface VPC endpoint, that enables you to privately access X-Ray APIs through private IP addresses.
  • AWS PrivateLink restricts all network traffic between the VPC and ECR to the Amazon network. You don’t need an internet gateway, a NAT device, or a virtual private gateway.

AWS Certification Exam Practice Questions

  • Questions are collected from Internet and the answers are marked as per my knowledge and understanding (which might differ with yours).
  • AWS services are updated everyday and both the answers and questions might be outdated soon, so research accordingly.
  • AWS exam questions are not updated to keep up the pace with AWS updates, so even if the underlying feature has changed the question might not be updated
  • Open to further feedback, discussion and correction.
  1. A company is facing performance issues with their microservices architecture deployed on AWS. Which service can help them debug and analyze the issue? [CCP]
    1. AWS Inspector
    2. CodeDeploy
    3. X-Ray
    4. AWS Config

References

AWS_X-Ray