X-Ray

Helps developers analyze and debug applications utilizing microservice architechture

  • X-Ray is a Distributed Tracing System / Performan Monitoring System

Introduciton to X-ray

What is Micro-service architechture? Microservices is an architectural and organizational approach to software development where software is composed of small independent services that communicate over well-defined APIs.

These servcies are owned by small. self-contained teams.

Microservices architectures make applications easier to scale and fater to develop, enabling innovation and accelerating time-to-market for new features.

What is distributed Tracing? Distributed tracing, also called distributed request tracting, is a method used to profile and monitor apps, especially those built using microservices architecture. Distributed tracing helps pintpoint where failures occur and what causes poor performance.

What is Performance Monitoring? Monitoring and management of performance and availability of software apps. APM strives to detect and diagnose complex application performance problems to maintain an expected level of service

X-ray is a Distributed Tracing System

  • Collects data about requests that your application servcies
  • View, filter collected data to identify issues and avenues for optimization

For any tracted request to tour application, your can see detailed information not onlu about the request and reponse, but also about calls that your application makes to downstream AWS resources, microservices, databases, and HTTP web APIs.

The Anatomy of X-ray

The X-RAy SDK provides:

  • Interceptors to add to your code to trace incoming HTTP requests
  • Client handlers to instrument AWS SDK clients that your application uses to call other AWS services
  • A HTTP client to use to instrument calls to other internal and external HTTP web servcies

The SDK also supports instrumenting calls to SQL databases, automatic AWS SDK client instrumentation, and other features

X-Ray - instrumentation

What is intrumenting? The ability to monitor or measure the level of a products performance, to diagnore errors, and to write trace information

X-Ray Daemon

Instead of sending trace data directly to X-Ray, the SDK sends JSON segment docuements to a daemon process listening for UDP traffic

The X-Ray daemon buffers segments in a queue and uploads them to X-Ray in batches.

X-Ray Concepts

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

  • Segments
  • Sub-Segments
  • Service graph
  • Traces
  • Sampling
  • Tracing Header
  • Filter Expressions
  • Groups
  • Annotations and Metadata
  • Errors, Faults, & Exceptions

Service Graph

The service graph shows the client, your front-end services and backend services

Segments

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

A segment can send the following information:

  • The host hostname, alias or IP address
  • The request method, client, path , user Autogenerated
  • The repsonse status, content
  • The work done start and end times, sub-segments
  • Issues that occur errors, faults, and exceptions, including automatic capture of exception stacks.

Sub-Segments

Sub-segments provide more granular timing infomation and details about downstream calls that your app made to fulfill the original request.

A sub-segment can contain additional details about a call to an AWS service, and external HTTP API, or SQL database.

You can even define arbitrary sub-segments to instrument speficic functions of lines of code in your application.

Traces

A trace collects all segments geneated by a single request.

A trace ID tracks the path of a request through your application.

The first supported service that HTTP request interacts with adds a trace ID header to the request, and propagates it downstream to track the latency, disposition, and other request database.

Sampling

The X-Ray SDK uses a sampling alogithm top determine which requests get traced.

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

Why only 5%? Keep costs low.

You can modify the default sampling rule and add additional sampling rules.

Trace Header

All requests are traced, up to a configurable minimum.

After reaching that minimum, a percentage of requests are traced to avoid unncessary cost.

The sampling decision and trace ID are added to HTTP requests in tracing headers named X-Amzn-Trace-Id;

Filter Expressions

Even with sampling, a complex application generate a lot of data; You can use Filter Expressions to narrow downs specific paths or users.

Groups

You can assign a Filter Expression to a Group so you can easily

You can call the group by name or by Amazon Resource Name (ARN) to gernate its own service graph, trace summaries, and Amazon CloudWatch metrics

Updating a group’s filter epxression doesn’t change data that’s aleady recorded The update only applied to subseqeunt traces.

This can request ina merged graph of new and old Expressions

To avoid this, delete the current group and create a fresh one.

Annotations and Metadata

You can add other information to the segment docuement as annoations and metadata.

Annotations and metadata are aggregated at the trace level, and can be added to any segment / subsegment

Annotations key-value pairs that are indexed for use with filter epxressions. X-Ray indexes up to 50 annotations per traced.

Metadata key-value pairs that are not indexed. The values can be of any type, including objects and lists.

Errors, Faults, and Exceptions

When an exception occurs while your app is serving an instrumented request the X-Ray SDK records exception details and the stack trace (if available)cost__.

ErrorClient errors400 / 4XX errors
FaultServer faults500 / 5xx errors
ThrottleThrottling errors429 Too Many Requests

You can view exceptiosn under the segment details in the X-Ray console.

AWS Service Integrations

  • Lambda
  • API Gateway
  • Elastic Load Balaneer (ELB)
  • Simple Notification Service (SNS)
  • Simple Queue Service (SQS);

Supported Languages

  • Go
  • Node.js
  • Ruby
  • PHP
  • Java
  • Python
  • Dotnet

[[x-ray]]