XRay Tracing

XRay Tracing

LocalStack Pro allows to instrument your applications using XRay tracing. This helps in optimizing the interactions between service calls, and facilitates debugging of performance bottlenecks.

For example, a Python Lambda function can be instrumented as follows (based on the example here):

import boto3
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch
s3_client = boto3.client('s3')

def lambda_handler(event, context):
    # your function code goes here...

Running this code in Lambda on LocalStack will result in two trace segments being created in XRay - one from the instrumented boto3 client when running create_bucket(..), and one for the custom subsegment denoted 'my_code'. You can use the regular XRay API calls (e.g., GetTraceSummaries, BatchGetTraces) to retrieve the details (timestamps, IDs, etc) of these segments.

You can also checkout another of our examples with Xray and Lambda, deployed via the Serverless framework, here