-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQS Tracing with AWSTraceHeader #208
Comments
Hi @rogueai, 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. |
Hi @willarmiros, |
Unfortunately we cannot provide dates for upcoming features. However this feedback is appreciated so we and the other teams involved in the change can prioritize the feature. Stay tuned for updates! |
Hi @willarmiros, Also, vote to move this feature on the top for your team backlog. Our team also waiting for this improvement to have a clear map on X-Ray. I hope it will not take to much to move it on live. Thank you! |
+1 |
+1. I have the same issue on my project |
+1 |
+1. I am also struggling with this limitation. |
+1 |
would love to have this aswell, it would signficantly improve the value of xray. |
We also really want to see a more connected map. We use this Lambda -> SNS -> SQS -> Lambda across 3 serverless applications, and X-Ray would enable us to monitor the entire flow |
+1 |
1 similar comment
+1 |
+1 Would love to see this feature supported as well as this would provide significant insight on the traces for our message processing workflow. |
this is needed greatly! otherwise, you cannot use xray with lambdas effeciently |
Thanks everyone, for the +1! The X-Ray Service Team is hard at work on this. We hope to post an update on this soon - thank you for you continued patience. Stay healthy and safe! |
@rogueai How did you manage to get SNS -> SQS to come up in the servicemap ? My request tracing gets stopped at SNS. (SQS doesnt showup on the service map) |
It feels to me like the "enhancement" label on this issue is debatable. From what I can see, this means that it is impossible to use X-Ray for its primary intended purpose (transaction visualisation across services) when using SQS and Lambdas? It doesn't look like there's any kind of workaround or hack to get around this in the meantime, so it essentially makes X-Ray unusable if your architecture just happens to include Lambdas and SQS? I would have thought this would constitute a somewhat more serious defect... |
+1 |
2 similar comments
+1 |
+1 |
Hello @pdeak, |
+1 |
2 similar comments
+1 |
+1 |
+3 |
I would dare to disagree. Wiring up Jaeger tracing for instance works flawlessly, propagating tracing ID through lambda -> sns -> sqs -> lambda without any issue. It takes extra ~5 lines of code per lambda, but other than that it's fairly easy. So if 3rd party can, why AWS can't? |
@ofcoursedude There's a difference between implementing tracing inside Lambdas with a custom code (like you mentioned with Jagger) and making it work with no code involved at all (like enabling X-Ray at API Gateway level). I think what they want to do is to have an option to pass traces through SQS without ANY additional code from our side. That forces them to implement this inside SQS which, as I mentioned, might be harder. But I'm only playing devil's advocate here. Anyway, an article about Jaeger tracing inside SQS/Lambdas and how did you set that up with some examples would be a great read, appreciated by many. I looked it up and there are little (if any) resources concerning that topic so far. |
I understand that - however, my point is that if I am able to pass a tracing information from one lambda to another through a chain of SNS and SQS through my code that I investigated and PoC'ed in one afternoon, I am really puzzled why there is no progress on this, especially given that the X-Ray SDK actually allows to switch tracing context on other platforms (so you can pass the tracing header in message's metadata like I did with Jaeger) but trying to do that in lambda runtime does not work. I really wonder what makes it so different on this level from "regular" runtimes (in my case .Net). |
+1 |
Hi all, I would first like to apologize that this capability is still not available. We hear you and understand your frustration. While we have been continuously working on delivering this, there have been major setbacks due to the complicated nature of the problem. As some have pointed out, we would like to provide a fully-managed solution for propagating trace context from SQS -> Lambda, however that has proven difficult because it is unclear how to map a batch of (independently traced) SQS messages to a single Lambda invocation (represented by 1 segment). We are still actively working on such a solution, and appreciate the constructive feedback we've received so far. In parallel, we're working with the Lambda team on possible workarounds to this problem. Once either is officially supported, we will update this issue. |
+1 |
+1 this capability is much sought after. |
Hi @willarmiros, do you have any news for us? |
+1 . Been a while. Is there an update here? |
Any update on this? After 3 years we still can't trace a flow between SQS and a Lambda function? |
Here is a workaround inspired from
Everything is done on the Lambda consumer side: import { Segment, setSegment, utils } from "aws-xray-sdk";
function createLambdaSegment(context, sqsRecord) {
const lambdaExecStartTime = new Date().getTime() / 1000;
const traceHeaderStr = sqsRecord.attributes.AWSTraceHeader;
const traceData = utils.processTraceData(traceHeaderStr);
const sqsSegmentEndTime = Number(sqsRecord.attributes.ApproximateFirstReceiveTimestamp) / 1000;
const segment = new Segment(
context.functionName,
traceData.root,
traceData.parent
);
segment.origin = "AWS::Lambda::Function";
segment.start_time = lambdaExecStartTime - (lambdaExecStartTime - sqsSegmentEndTime);
segment.addPluginData({
function_arn : context.invokedFunctionArn,
region : sqsRecord.awsRegion,
request_id : context.awsRequestId
});
return segment;
}
/**
* Set the current Lambda segment that instruments SQS.
*
* This is a workaround for https://github.com/aws/aws-xray-sdk-node/issues/208.
*
* Implementation inspired from:
* - https://dev.to/aws-builders/x-ray-tracing-from-sqs-to-lambda-8md
* - https://github.com/kyhau/aws-tools/blob/main/X-Ray/xray-sqs-to-lambda/handler.ts
*
* @see https://github.com/aws/aws-xray-sdk-node/issues/208#issuecomment-1285169865
* @param {object} context Lambda [context](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html)
* @param {object} sqsRecord SQS [record item](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html)
* @returns {object} X-Ray segment for Lambda
*/
export default function setLambdaSegmentFromSQS(context, sqsRecord) {
const segment = createLambdaSegment(context, sqsRecord);
setSegment(segment);
return segment;
} And you use it like that in your handler file: import setLambdaSegmentFromSQS from "./setLambdaSegmentFromSQS";
export async function handle(event, context) {
const segment = setLambdaSegmentFromSQS(context, event.Records[0]);
try {
await handleCore(event);
} catch (err) {
segment.close(err);
throw err;
}
segment.close();
} And with a proper X-Rray trace group it gets cleaner: XRayTraceGroup:
Type: AWS::XRay::Group
Properties:
GroupName: my-group
InsightsConfiguration:
InsightsEnabled: true
NotificationsEnabled: false
FilterExpression: !Sub |
resource.arn = "${ProducerFunction.Arn}"
OR resource.arn = "${Queue.Arn}"
OR resource.arn = "${CollectorFunction.Arn}" |
@yvele Thanks for sharing. Only if there was a timeline to this feature request, we'd have known if it's worth jumping on the workarounds already. This looks great though, Thanks much! |
Hi everyone - unfortunately we are not able to share any timelines about new features over GitHub. However this issue will be updated the moment we have a publicly available update. |
Assuming this is a resolution? |
Yes, it is ❤ |
As a couple astute commenters have noticed, today we are thrilled to announce support for linking traces from SQS Queues that are polled by AWS Lambda functions! This functionality is available out of the box for all Lambda functions with Active Tracing enabled triggered by SQS Queues. I'm only the messenger here, so I'd like to thank all of the other engineers who put in so much hard work to deliver this feature! Learn more here: https://aws.amazon.com/about-aws/whats-new/2022/11/aws-x-ray-trace-linking-event-driven-applications-amazon-sqs-lambda/ Please use the built-in feedback link on the AWS Console, reach out to your AWS Support contact, or of course open issues on the SDK repos to leave feedback for X-Ray, there is more to come! With that, I'll be closing this issue out. |
Great! So glad to see an update here. However, the complete flow mentioned in the topic is still not supported (Lambda -> SNS -> SQS -> Lambda) I believe? I can't see SNS -> SQS flow in my traces @willarmiros |
Good callout @s1mrankaur - we will continue to track the SNS -> SQS case in this issue: aws/aws-xray-sdk-go#218 We will also update here when that workflow is fully supported :) |
Hi folks, wanted to cross-post here that today we are happy to announce Amazon SNS support for active tracing with X-Ray! If you have an SNS->SQS->Lambda workflow for example, you will now be able to see that workflow end-to-end for the first time by opting in to active tracing on your SNS topic. Read more here: https://aws.amazon.com/about-aws/whats-new/2023/02/amazon-sns-x-ray-active-tracing-visualize-analyze-debug-application-performance/ |
@willarmiros This is amazing! I am guessing there isn't support for this in a serverless framework yet i.e opting for active tracing on SNS topics?
This is what I have sofar. Is there any additional config that I can add/enable to see this in action? @willarmiros |
The active tracing config is supported via CloudFormation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-topic.html#cfn-sns-topic-tracingconfig I am not sure how that makes its way over to the serverless framework tbh, but if there is a place to put in that request with them I'd love to do so! |
Thanks @willarmiros . I've now posted the feature request here serverless/serverless#12385 |
What about DynamoDB Streams and lambdas? Is it anywhere on the roadmap? |
Hi,
I have an SQS queue subscribed to an SNS topic and in turns triggers a Lambda on new SQS messages.
I've tried following the docs here: https://docs.aws.amazon.com/xray/latest/devguide/xray-services-sqs.html to create segments related to SQS, but so far everything I tried didn't work.
I've added a segment this way:
What this produces though is something like this:
As you can see, the SQS segment is created with SNS as a parent, however the Lambda invocation is disconnected.
I've also tried other approaches that didn't work:
_X_AMZ_TRACE_ID
env variable with the AWSTraceHeader, before initializing the XRay SDKCould you advise a possible workaround, to get this working?
Thank you!
The text was updated successfully, but these errors were encountered: