spring-cloud-sleuth 与 spring-amqp 的集成
spring-cloud-sleuth integration with spring-amqp
我只是使用 spring-cloud-sleuth
迈出第一步,它适用于所有类型的 http 调用。
现在我也在尝试涵盖消息传递部分。我看到 spring-cloud-sleuth
与 spring-integration
集成开箱即用。我目前只使用 spring-amqp
。还有一种方法可以使它正常工作吗?有没有人有一些见解甚至代码示例?
目前我们仅通过 spring-integration 直接支持 AMQP。为了支持 AMQP,您必须确保发送的所有消息都设置了正确的 headers,当您取回它们时,您必须将这些 headers 放入本地上下文中。向消息中注入 Span(跟踪)信息例如在此处完成 -https://github.com/spring-cloud/spring-cloud-sleuth/blob/v1.3.5.RELEASE/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/MessagingSpanTextMapInjector.java and extracting tracing data from the message is here https://github.com/spring-cloud/spring-cloud-sleuth/blob/v1.3.5.RELEASE/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/MessagingSpanTextMapExtractor.java. In this method you have the setting of the extracted Span into the context https://github.com/spring-cloud/spring-cloud-sleuth/blob/v1.3.5.RELEASE/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceChannelInterceptor.java#L71
更新:
使用 Sleuth 2.0.x(Finchley 发布系列)如果您有 rabbit 模板类型的 bean(请参阅 here),它应该开箱即用。不需要额外的代码。
我只是使用 spring-cloud-sleuth
迈出第一步,它适用于所有类型的 http 调用。
现在我也在尝试涵盖消息传递部分。我看到 spring-cloud-sleuth
与 spring-integration
集成开箱即用。我目前只使用 spring-amqp
。还有一种方法可以使它正常工作吗?有没有人有一些见解甚至代码示例?
目前我们仅通过 spring-integration 直接支持 AMQP。为了支持 AMQP,您必须确保发送的所有消息都设置了正确的 headers,当您取回它们时,您必须将这些 headers 放入本地上下文中。向消息中注入 Span(跟踪)信息例如在此处完成 -https://github.com/spring-cloud/spring-cloud-sleuth/blob/v1.3.5.RELEASE/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/MessagingSpanTextMapInjector.java and extracting tracing data from the message is here https://github.com/spring-cloud/spring-cloud-sleuth/blob/v1.3.5.RELEASE/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/MessagingSpanTextMapExtractor.java. In this method you have the setting of the extracted Span into the context https://github.com/spring-cloud/spring-cloud-sleuth/blob/v1.3.5.RELEASE/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceChannelInterceptor.java#L71
更新:
使用 Sleuth 2.0.x(Finchley 发布系列)如果您有 rabbit 模板类型的 bean(请参阅 here),它应该开箱即用。不需要额外的代码。