AWS X-Ray Tracing from Lambda to SNS to SQS to another Lambda (Python3, boto3)
Question:
I have a question similar to this one. I want to generate a service map that allows me to view the orchestration of my serverless architecture, especially across SNS and SQS between 2 lambdas. The difference being that I am using Amazon’s SQS in place of RabbitMQ.
I saw this question, and the linked forum post in the answer suggests that this feature is already available.
From what I have read in the docs, it suggests that I only need to patch
the boto
library. Going by the examples, I included the following in my relevant python files:
from aws_xray_sdk.core import patch_all
patch_all()
However, when testing my lambda, the service map still appears as 2 individual traces, with the trace ending at my SNS.
Does anyone know what may be the issue here?
Answers:
AWS SNS currently lacks the capability to pass X-Ray trace context to SQS subscribers. It only supports HTTP/HTTPS and Lambda subscribers: https://docs.aws.amazon.com/xray/latest/devguide/xray-services-sns.html
As a result the trace is not propagated from SNS to SQS and therefore you see 2 disconnected traces.
Not tested yet but I found this post (2023-02-09) claiming the propagation is now supported:
https://aws.amazon.com/about-aws/whats-new/2023/02/amazon-sns-x-ray-active-tracing-visualize-analyze-debug-application-performance/
I have a question similar to this one. I want to generate a service map that allows me to view the orchestration of my serverless architecture, especially across SNS and SQS between 2 lambdas. The difference being that I am using Amazon’s SQS in place of RabbitMQ.
I saw this question, and the linked forum post in the answer suggests that this feature is already available.
From what I have read in the docs, it suggests that I only need to patch
the boto
library. Going by the examples, I included the following in my relevant python files:
from aws_xray_sdk.core import patch_all
patch_all()
However, when testing my lambda, the service map still appears as 2 individual traces, with the trace ending at my SNS.
Does anyone know what may be the issue here?
AWS SNS currently lacks the capability to pass X-Ray trace context to SQS subscribers. It only supports HTTP/HTTPS and Lambda subscribers: https://docs.aws.amazon.com/xray/latest/devguide/xray-services-sns.html
As a result the trace is not propagated from SNS to SQS and therefore you see 2 disconnected traces.
Not tested yet but I found this post (2023-02-09) claiming the propagation is now supported:
https://aws.amazon.com/about-aws/whats-new/2023/02/amazon-sns-x-ray-active-tracing-visualize-analyze-debug-application-performance/