Skip to main content

An unofficial shim which faciliates the creation of AWS Xray Segments in Lambda functions triggered by SQS.

Project description

https://github.com/Sam-Martin/aws-xray-sqs-lambda-segment-shim/blob/main/images/example.png?raw=true

It’s not currently possibly follow an AWS Xray trace through a Lambda Function triggered by an SQS Queue.

Unless you use aws-xray-sqs-lambda-segment-shim!

Installation

pip install aws-xray-lambda-segment-shim

Usage

from aws_xray_sqs_lambda_segment_shim import SQSTriggeredXrayRecorder


def lambda_handler(event, context):
    print(json.dumps(event, default=str))
    for i, record in enumerate(event["Records"]):
        recorder = SQSTriggeredXrayRecorder(
            record=record,
            lambda_request_id=context.aws_request_id,
            lambda_arn=context.invoked_function_arn,
        )
        with recorder.in_subsegment(f"SQS Record {i}") as subsegment:
            print(
                "I'm triggered by an SQS Record and using trace id ",
                subsegment.trace_id,
            )
        recorder.end_segment()

SQSTriggeredXrayRecorder is a child class of aws_xray_sdk.AWSXRayRecorder so you can use all the methods you would expect from following the aws-xray-sdk documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws_xray_sqs_lambda_segment_shim-0.3.0.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page