Spring boot Sleuth在b3单头中不包括RabbitMQ消息的ParentSpan

Spring boot Sleuth在b3单头中不包括RabbitMQ消息的ParentSpan,spring-boot,spring-cloud-sleuth,Spring Boot,Spring Cloud Sleuth,我最近从Spring Cloud Greenwich.SR2迁移到Hoxton.SR9,并使用Spring Sleuth跟踪传入的REST调用到我的Spring Boot应用程序,该应用程序触发最终到达RabbitMQ的消息 显然,Spring Sleuth在这两个版本之间的一个关键区别是,不再为trace、span和parentSpan发送3个单独的消息头,现在只发送一个b3头,形式为{trace}-{span}-{sample}-{parentSpan},最后两个组件是可选的 让我困惑的是,

我最近从Spring Cloud Greenwich.SR2迁移到Hoxton.SR9,并使用Spring Sleuth跟踪传入的REST调用到我的Spring Boot应用程序,该应用程序触发最终到达RabbitMQ的消息

显然,Spring Sleuth在这两个版本之间的一个关键区别是,不再为trace、span和parentSpan发送3个单独的消息头,现在只发送一个
b3
头,形式为
{trace}-{span}-{sample}-{parentSpan}
,最后两个组件是可选的

让我困惑的是,到达RabbitMQ的消息上的b3头似乎从来没有parentSpan组件。e、 g.顺序如下:

  • 在应用程序REST控制器内:traceId=T,spanId=S1,parentSpanId=S0
  • 从应用程序内发送事件之前:traceId=T,spanId=S2,parentSpanId=S1
  • RabbitMQ队列上的消息头:b3=T-S2-1
  • 换句话说,消息头具有正确的跟踪,但在应用程序中共享发送事件上下文的范围,并且具有noparentSpan

    这是预期的吗?我确信,如果使用以前版本的Sleuth,我会在消息头中看到一个新的spanId,并且在发送事件上下文中看到一个与span相等的parentSpan

    我是否误解了正在发生的事情,或者(如果我的预期是合理的)是否有办法改变这种默认行为

    我有以下明确的侦探属性设置:

    spring.sleuth.enabled=true
    spring.messaging.enabled=true
    spring.supportsJoin=false
    
    (注意:我在supportsJoin defaulted上也做了同样的尝试,但对于缺少parentSpanId似乎没有任何影响)

    调试信息

    这是我通过单步执行调试器所能确定的:

  • 我们将
    GenericMessage
    传递到
    AbstractMessageChannel.send()
  • 最后,消息被传递到
    TracingChannelInterceptor.preSend()
  • TracingChannelInterceptor
    配置了一个
    DeferredInjector
    ,其中
    setter
    MessageHeaderPropagation
    的一个实例,而
    injectorFactory
    具有一个
    producerinjector函数=单个父对象
  • TracingChannelInterceptor.preSend()
    方法调用
    DeferredInjector.inject(span.context(),headers)
    ,这导致单\u NO \u父注入器向传出消息添加一个
    b3
    头,格式为
    {traceId}-{spanId}-1
  • 因此,缺少parentSpanId似乎源于这样一个事实,即TracingChannelInterceptor.injector是一个延迟喷射器,其生产者喷射器是单\u否\u父对象

    自定义配置

    注册以下bean以覆盖默认传播设置会将行为更改为:

  • 在应用程序REST控制器内:traceId=T,spanId=S1,parentSpanId=S0
  • 从应用程序内发送事件之前:traceId=T,spanId=S2,parentSpanId=S1
  • RabbitMQ队列上的消息头:b3=T-S2-1-S1
  • 但我想知道为什么有必要这么做

    @Configuration
    public class B3Configuration {
      @Bean
      Propagation.Factory customPropagationFactory() {
        return B3Propagation.newFactoryBuilder()
            .injectFormat(B3Propagation.Format.SINGLE)
            .injectFormat(Span.Kind.CLIENT, B3Propagation.Format.SINGLE)
            .injectFormat(Span.Kind.CONSUMER, B3Propagation.Format.SINGLE)
            .injectFormat(Span.Kind.PRODUCER, B3Propagation.Format.SINGLE)
            .build();
      }
    }
    

    默认的
    b3.Format
    似乎已更改,您可以在以下位置看到当前的格式:


    //注意:您是否碰巧有一个复制该问题的示例项目?Hi Jonatan-我现在没有什么东西,但如果有帮助的话,我可能会把一些简单的东西放在一起。Spring Boot 2.3.7和Spring Cloud Hoxton.SR9是一个非常普通的Spring Boot设置。目前我还没有找到源代码,但我确实尝试在Spring Boot应用程序中调试了它,它使用了Format.SINGLE\u NO\u PARENT,而不是Format.SINGLE,在传出Spring消息的拦截器上下文中使用Format.SINGLE。很抱歉,我现在不能说得更具体。@JonatanIvanov我在原始问题中添加了一些调试信息,希望对您有所帮助-如果您需要更多信息,请告诉我。@JonatanIvanov“问题”(如果是问题)似乎是通过注册问题文本中包含的bean来解决的。但是我很惊讶我必须这样做才能让它这样工作。感谢您查看这个@JonatanIvanov,以及关于使用
    BaggagePropagation.newFactoryBuilder
    的有用建议。我查看了问题链接,但不确定结论-这种默认行为(使用单亲家长)正确吗?结果对我来说似乎很奇怪。