Search code examples
amazon-web-servicesaws-lambdaserverlessaws-xray

Tracking of Common Services in AWS using X-ray


I have multiple Lambdas and each of them either invoke another lambda or a rest API or a dynamoDB or S3 etc .

Example :

  • HotelBooking
  • FlighBooking

These invoke the common services like

  • BookingService
  • InvoiceService

I need to track which application i.e Flight Booking / HotelBooking is invoking the booking service and how many times / how much CPU etc

Is this possible through X-Ray in AWS or any other better ways ?


Solution

  • After some research, I believe annotation is the best way for the above problem

    So we need to add an annotation in NodeJS

                AWSXRay.captureFunc('annotations', (subsegment) => {
                    subsegment.addAnnotation('application', "BookingService");
                });

    Annotations are indexed and can be used to filter too using an expression like this annotation.= "BookingService"

    more Info : X-ray merges segments, Subsegments to traces so the annotation at subsegment level is enough for filtering the traces