6

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.

dvisco
  • 461
  • 5
  • 12

1 Answers1

4

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

Ruslan
  • 3,063
  • 1
  • 19
  • 28
  • In regards to SQS, I assumed there potentially would be support for a property in the SQS message that 'could' contain the parent id of the segement for what ever service enqueued the message. If the SQS client is not aware of XRay to a degree how could you string a flow from the source of SQS to the sink? I'd want those requests to be connected in the X-Ray service map. Thanks for the links and guidance however! Do appreciate the detail. – dvisco Sep 07 '17 at 13:27
  • The SQS client is aware of X-Ray and that is how it creates those "artificial" inferred segments. As for connecting from the source of SQS to the sink - not sure if it could make sense, since that is an async part that is not blocking the initial thing that put the source SQS message. – Ruslan Sep 09 '17 at 06:47
  • @dvisco Keep in mind that X-Ray is fundamentally about breaking down the performance parts per request. Let's say you have a web request that puts a message to SQS. That put operation blocks the processing for a little while and that's important to see in the request's subsegments. But then something reads that SQS message which is a separate process and doesn't put any burden to the execution time of the initial request. – Ruslan Sep 09 '17 at 09:00
  • Thanks again, I agree I should think about it in the light, that I'm looking to profile async parts of my application. – dvisco Sep 09 '17 at 14:58