带有 Java SQS JMS 连接器的 AWS Xray

AWS Xray with Java SQS JMS connector

我们最近开始将 AWS Xray 添加到我们的 Spring 项目中,并成功利用 AWSXRayServletFilter 创建 Segments 来满足我们的客户请求。

现在我们也开始添加 AWS SDK Instrumentor 来跟踪我们对 AWS 服务的使用情况。其中之一是 SQS,我们使用 amazon-sqs-java-messaging-lib 来利用 JMS 来接收 SQS 消息。这就是我们遇到麻烦的地方。

每次我们的应用程序尝试获取消息时,TracingHandler 都会尝试创建一个 SubSegment 并失败,因为尚未创建 Segment。我们如何将这些请求包装在 Segment 中?该信息不会包含在消息本身中,与将消息推送到队列的资源 link 分段在一起吗?

我本来希望有 Context Missing 策略可用于创建一个段,如果一个丢失或至少从父跟踪 ID 中获取,但我没有看到他们最新的 docs 中包含该信息.

这是一个已知问题,已经在官方论坛上讨论过了。这里有几个链接: 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?

段信息保存在 ThreadLocal 中。如果您在单独的线程中 运行 某些东西,则必须手动创建一个段,因此在创建子段时您将拥有所需的 ThreadLocal 数据。 SQS 消息甚至与 X-Ray 服务相关的 SQS 服务本身都没有什么特别之处。它仅使用 SQS 客户端,使 X-Ray 通过使用处理程序跟踪 ThreadLocal 数据来推断对 SQS 的调用已经发生。

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.

这是我的功能请求之一。查看线程及其官方答案以及我在尝试自己实施此类上下文缺失策略时发现的当前限制。 https://forums.aws.amazon.com/thread.jspa?threadID=252012&tstart=0