Observability: Tracing in AWS Lambdas using AWS X-Ray

A. Create a Lambda Layer for aws-xray-sdk python package

❯ ll pythontotal 72drwxr-xr-x   3 user  user    96B Nov 17 14:04 __pycache__drwxr-xr-x   8 user  user   256B Nov 17 14:04 aws_xray_sdkdrwxr-xr-x  10 user  user   320B Nov 17 14:04 aws_xray_sdk-2.8.0.dist-infodrwxr-xr-x   6 user  user   192B Nov 17 14:04 bindrwxr-xr-x  44 user  user   1.4K Nov 17 14:04 botocoredrwxr-xr-x   9 user  user   288B Nov 17 14:04 botocore-1.23.7.dist-infodrwxr-xr-x  14 user  user   448B Nov 17 14:04 dateutildrwxr-xr-x  11 user  user   352B Nov 17 14:04 futuredrwxr-xr-x   8 user  user   256B Nov 17 14:04 future-0.18.2-py3.9.egg-infodrwxr-xr-x  11 user  user   352B Nov 17 14:04 jmespathdrwxr-xr-x  10 user  user   320B Nov 17 14:04 jmespath-0.10.0.dist-infodrwxr-xr-x   7 user  user   224B Nov 17 14:04 libfuturizedrwxr-xr-x   6 user  user   192B Nov 17 14:04 libpasteurizedrwxr-xr-x   8 user  user   256B Nov 17 14:04 pastdrwxr-xr-x   9 user  user   288B Nov 17 14:04 python_dateutil-2.8.2.dist-infodrwxr-xr-x   8 user  user   256B Nov 17 14:04 six-1.16.0.dist-info-rw-r--r--   1 user  user    34K Nov 17 14:04 six.pydrwxr-xr-x  17 user  user   544B Nov 17 14:04 urllib3drwxr-xr-x   8 user  user   256B Nov 17 14:04 urllib3-1.26.7.dist-infodrwxr-xr-x   8 user  user   256B Nov 17 14:04 wraptdrwxr-xr-x   8 user  user   256B Nov 17 14:04 wrapt-1.13.3-py3.9.egg-info

B. Enable X-Ray in the Lambda Configuration

C. Updates to the Lambda Code Base

import boto3
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch_all
logger = logging.getLogger()
logger.setLevel(logging.INFO)
patch_all()

D. Let’s Navigate through X-Ray Console

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Suleman Hasib

Suleman Hasib

I do DevOps. Being an entrepreneur is just the DNA. Oh and a *nix fanboy.