-
Notifications
You must be signed in to change notification settings - Fork 113
Description
I've spent many hours trying to get Lambda -> SNS -> SQS -> Lambda to work in xray, and all my traces end with SNS, never going through to SQS and the next lambda.
My code is not very complicated.
sess := session.Must(session.NewSession())
client := sns.New(sess)
xray.AWS(client.Client)
// do some work
_, err = client.PublishWithContext(ctx, msg)
AWS documentation says that SNS and SQS should automatically pass on the tracing header to the next lambda, and I can't see anything on my SQS queues configuration to enable tracing, it should just work, right?
I eventually found this comment on the NodeJS library:
aws/aws-xray-sdk-node#208 (comment)
This is a known issue with propagating trace context through an SQS queue. It is not currently possible to connect a trace passed into an SQS queue to the Lambda consuming it on the other end. This is because although the trace header is propagated in the SQS message, you cannot set it in the Lambda because segments in Lambda are immutable.
Enabling this functionality is a feature that is in progress and one we hope to release for all our SDKs. Stay tuned and I will update this issue as we make progress in the Node SDK.
Can you confirm if the golang library has the same issue (due to an underlying issue with Lambda perhaps?) and there is no way of it working (and I am wasting my time trying)?
The only other thing I found was this https://docs.aws.amazon.com/xray/latest/devguide/xray-services-sqs.html which shows some code to manually recreate a segment (Excuse the Java code)
// Retrieve the trace header from the AWSTraceHeader message system attribute
String traceHeaderStr = message.getAttributes().get("AWSTraceHeader");
if (traceHeaderStr != null) {
TraceHeader traceHeader = TraceHeader.fromString(traceHeaderStr);
// Recover the trace context from the trace header
Segment segment = AWSXRay.getCurrentSegment();
segment.setTraceId(traceHeader.getRootTraceId());
segment.setParentId(traceHeader.getParentId());
segment.setSampled(traceHeader.getSampled().equals(TraceHeader.SampleDecision.SAMPLED));
}
I assume this isn't possible in Lambda for the reasons above (lambda segments being immutable)?