Skip to content

event notification from separate application breaking xray tracing

0

I've built an application that incorporates two pathways.

One pathways involves a script that creates messages and delivers them to a standard SQS queue (queue A). This queue in turn triggers a lambda, which does some other stuff.

The other pathways is an event notification from an S3 bucket (which is triggered when a particular type of file is put in the bucket) that creates messages in a second SQS queue (queue B). This queue in turn triggers the same lambda as above. In my QA account, this S3 bucket is created using CDK. In Prod, the S3 bucket exists in a separate account that I don't manage (let's call this bucket "Alpha"). The administrator of that account has set up the necessary permissions and has created the event notification with queue B as the destination.

The lambda is instrumented and has xray tracing enabled.

Xray works great in QA, and it works great in Prod using the first pathway. But the second pathway in Prod doesn't allow Xray to work properly. After much debugging, it appears that the messages forwarded by the event notification from the S3 bucket Alpha have an AWSTraceHeader with the "Sampling" attribute set to 0. This means that any subsegments I try to create within my lambda end up being dummy segments (i.e. not sampled).

This appears to be because the root segment is created by the service that actually sent the file to bucket Alpha. And since that service (which is managed by the administrator of this separate account) does not have xray tracing enabled, it seems that my application is doomed.

I have tried numerous approaches to re-establish a root segment from my lambda, but have been unsuccessful.

Is there any solution here?

asked 2 years ago282 views

1 Answer
0

This is indeed a challenging situation, and you've correctly identified the root cause of the issue. When the X-Ray trace header is propagated from an upstream service that doesn't have X-Ray tracing enabled, it can lead to the scenario you're experiencing where the sampling decision is set to 0, effectively disabling tracing for downstream services.

Unfortunately, there isn't a straightforward way to override the sampling decision that's been propagated from the upstream service. The X-Ray SDK respects the sampling decision made by the root service to maintain consistency across the entire trace.

However, there are a few potential approaches you could consider:

  1. Work with the administrator of the separate account: The ideal solution would be to enable X-Ray tracing on the service that's putting files into bucket Alpha. This would ensure that proper tracing is in place from the beginning of the request flow.

  2. Implement custom tracing: Instead of relying solely on X-Ray's automatic tracing, you could implement custom tracing within your Lambda function. This won't override the X-Ray sampling decision, but it would allow you to capture and log important information about the execution path.

  3. Use a different tracing solution: If X-Ray tracing is crucial for your application and you can't get it working with the current setup, you might consider implementing an alternative tracing solution that you have more control over.

  4. Implement a workaround in your Lambda: You could check the sampling decision at the start of your Lambda function. If it's set to 0, you could potentially create a new trace or segment. This wouldn't be connected to the upstream trace, but it would at least give you visibility into your Lambda's execution.

  5. Use CloudWatch Logs: While not a replacement for distributed tracing, ensuring comprehensive logging in your Lambda function can provide valuable insights when X-Ray tracing is not available.

Remember that these approaches have their own trade-offs and limitations. The best long-term solution would likely involve collaboration with the team managing the upstream service to ensure consistent tracing across the entire application flow.
Sources
Amazon SQS and AWS X-Ray - AWS X-Ray
Batch Processing - Powertools for AWS Lambda (Python)

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.