spring-cloud-starter-sleuth + axon-tracing-spring-boot-starter =?

问题描述

标题说明了一切。是否可以让 spring-cloud-starter-sleuth 与 axon-tracing-spring-boot-starter 一起工作?

当前日志输出

    2021-06-02 15:12:36.449  INFO [,2b2fc6a322588b0e,114b332e7847e95f] 14716 --- [nio-8082-exec-5] o.a.m.interceptors.LoggingInterceptor    : dispatched messages: [FindAll]
2021-06-02 15:12:36.455  INFO [,] 14716 --- [ueryProcessor-9] o.a.m.interceptors.LoggingInterceptor    : Incoming message: [FindAll]
2021-06-02 15:12:36.542  INFO [,] 14716 --- [ueryProcessor-9] o.a.m.interceptors.LoggingInterceptor    : [FindAll] executed successfully with a [ArrayList] return value
2021-06-02 15:12:36.668  INFO [,114b332e7847e95f] 14716 --- [nio-8082-exec-5] o.a.m.interceptors.LoggingInterceptor    : dispatched messages: [KlassificeraApplikationCommand]
2021-06-02 15:12:36.724  INFO [,] 14716 --- [mandProcessor-0] o.a.m.interceptors.LoggingInterceptor    : Incoming message: [KlassificeraApplikationCommand]
2021-06-02 15:12:36.785  INFO [,] 14716 --- [mandProcessor-0] o.a.m.interceptors.LoggingInterceptor    : [KlassificeraApplikationCommand] executed successfully with a [null] return value
2021-06-02 15:12:36.785  INFO [,] 14716 --- [mandProcessor-0] o.a.m.interceptors.LoggingInterceptor    : dispatched messages: [ApplikationKlassificeradEvent]
2021-06-02 15:12:36.808 TRACE [,114b332e7847e95f] 14716 --- [nio-8082-exec-5] org.zalando.logbook.Logbook              : Incoming Request: null

所需的日志输出

2021-06-02 15:12:36.449  INFO [,114b332e7847e95f] 14716 --- [ueryProcessor-9] o.a.m.interceptors.LoggingInterceptor    : Incoming message: [FindAll]
2021-06-02 15:12:36.542  INFO [,114b332e7847e95f] 14716 --- [ueryProcessor-9] o.a.m.interceptors.LoggingInterceptor    : [FindAll] executed successfully with a [ArrayList] return value
2021-06-02 15:12:36.668  INFO [,114b332e7847e95f] 14716 --- [mandProcessor-0] o.a.m.interceptors.LoggingInterceptor    : Incoming message: [KlassificeraApplikationCommand]
2021-06-02 15:12:36.785  INFO [,114b332e7847e95f] 14716 --- [mandProcessor-0] o.a.m.interceptors.LoggingInterceptor    : [KlassificeraApplikationCommand] executed successfully with a [null] return value
2021-06-02 15:12:36.785  INFO [,114b332e7847e95f] 14716 --- [mandProcessor-0] o.a.m.interceptors.LoggingInterceptor    : dispatched messages: [ApplikationKlassificeradEvent]
2021-06-02 15:12:36.808 TRACE [,114b332e7847e95f] 14716 --- [nio-8082-exec-5] org.zalando.logbook.Logbook              : Incoming Request: null

解决方法

看来 axon-tracing-spring-boot-starter 正在使用 OpenTracing。 OpenTracing 是一个被放弃的跟踪库,它从未达到 GA/稳定版本。因此,即使有一种简单的方法,我也不会在生产中使用 OpenTracing,我会尽量远离它。

从 3.0 版本开始,Spring Cloud Sleuth 已经将 tracer 抽象出来,并且它支持多个 tracer 实现。默认情况下,它支持 Brave,这是一个成熟的跟踪库,但 Sleuth 也支持 OpenTelemetry (Sleuth-OTel)。 OpenTelemetry 支持正在孵化中,不建议在产品中使用,因为 OpenTelemetry Tracing 对于 Java 还不是完全稳定/GA。

有了这个,您的选择是:

  1. 为 Brave 添加对 Axon 的支持
    这就是我的建议,我会先为他们打开一个问题
  2. OpenTelemetry 理论上与 OpenTracing 兼容(查看 OpenTelemetry 文档)
    您也许可以使用 Sleuth-OTel 和 OpenTracing 这样做的问题是:OpenTracing 被放弃了,从来没有 GA,OpenTelemetry Java Tracing 还不稳定,Sleuth-OTel 还不稳定
  3. 您可以为 Sleuth 实现 OpenTracing 支持
    我认为这是一个坏主意,它需要大量工作,而且 OpenTracing 已被放弃且从未正式发布