We've recently begun adding in AWS Xray into our Spring project and had success utilizing the AWSXRayServletFilter
for creating Segments
to cover our client requests.
Now we've also begun adding in the AWS SDK Instrumentor to trace our usages of AWS services. One of which is SQS, which we use amazon-sqs-java-messaging-lib
to utilize JMS to receive SQS messages. This is where we are facing some trouble.
Every time our application attempts to get messages the TracingHandler
attempts to create a SubSegment
and fails because there is no Segment
already created. How can we wrap these requests in a Segment
? Wouldn't that information be contained in the message itself to link segments together from the resource that pushed the message to the queue?
I would have expected there to Context Missing strategy available to create a Segment if one is missing or at least pick up from a parent trace id but I don't see that information contained within their latest docs.
This is a known problem that has been discussed on the official forum. Here is a couple of links: https://forums.aws.amazon.com/thread.jspa?threadID=252012&tstart=0 https://forums.aws.amazon.com/thread.jspa?threadID=257258&tstart=25
Every time our application attempts to get messages the TracingHandler attempts to create a SubSegment and fails because there is no Segment already created. How can we wrap these requests in a Segment? Wouldn't that information be contained in the message itself to link segments together from the resource that pushed the message to the queue?
The Segment info is kept in a ThreadLocal. You have to create a segment manually if you are running something in a separate thread and thus you'll have the required ThreadLocal data when it creates a subsegment. There is nothing special in the SQS messages and even the SQS service itself related to the X-Ray service. It's only using the SQS client that makes X-Ray infer that a call to SQS has happened by tracking ThreadLocal data with the handlers.
I would have expected there to Context Missing strategy available to create a Segment if one is missing or at least pick up from a parent trace id but I don't see that information contained within their latest docs.
That was one of my feature requests. See the thread with it along with an official answer and along with the current limitation that I found in a try to implement such a Context Missing Strategy myself. https://forums.aws.amazon.com/thread.jspa?threadID=252012&tstart=0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With