Skip to main content

XRay

Introdution

XRay provides Observability elements almost out of the box, and almost for all the different AWS services that can compose our distributed middleware.

We plan to use Xray as an interim solution, for the reasons exposed on the Current planning page.

What we get

With XRay enabled on every component, we can visualize metrics, traces & logs seamlessly, on a single page. (see below)

It also allows creating widgets based on metrics or Log Insights that can be added to dashboards, or use for setting alarms.

![TODO - FIX IMAGE]

How to use - Lambdas

Serverless allows us to set the active tracing flag on, Leticia Reigada has investigated on the ticket https://raphatech.atlassian.net/browse/PLT-78?focusedCommentId=66598

We need to import two packages on the lambda itself

import AWS from 'aws-sdk';
import AWSXRay from 'aws-xray-sdk';

const aws = AWSXRay.captureAWS(AWS);

How to visualize

Once ready, and Lambda has been executed, we can access directly the monitoring area of our Lambda, and we can view the Traces

![TODO - FIX IMAGE]

And access to the detail of any, where the Trace Map, Span segments & Logs are present. In the example below, we can visualize the flow of a request passing through 2 lambdas and Cognito, as part of the same trace.

![TODO - FIX IMAGE]

Thinking on a real scenario, we can create alarms based on metrics for our lambdas, which could detect, for example, an increasing number of errors that reaches the threshold. From there we could navigate to the traces of the failing lambda, and start investigating the possible causes.

Resources