how to force sleuth not send in single b3 header

Viewed 804

I'm using sleuth in my Spring Boot application for log tracing, and my application also send some messages via Active MQ, but when i see the message properties, it send the trace with a single b3 header. how can i configure sleuth to separate the headers?

2 Answers

The default is not only better performance, but doesn't violate JMS header name rules. I would advise you figure out why you cannot use b3 single.

If you must use multiple headers, you can do something like this:

@Bean Propagation.Factory customPropagationFactory() {
  return B3Propagation.newFactoryBuilder()
      .injectFormat(Span.Kind.PRODUCER, Format.MULTI)
      .injectFormat(Span.Kind.CONSUMER, Format.MULTI)
      .build();
}

If you want the spring.sleuth.baggage.xxx application properties to work, then you need to wrap your propagation factory in a baggage propagation factory:

@Bean
public BaggagePropagation.FactoryBuilder baggagePropagationFactoryBuilder() {
    Propagation.Factory b3Factory = B3Propagation.newFactoryBuilder()
            .injectFormat(Span.Kind.PRODUCER, B3Propagation.Format.MULTI)
            .injectFormat(Span.Kind.CONSUMER, B3Propagation.Format.MULTI)
            .build();
    return BaggagePropagation.newFactoryBuilder(b3Factory);
}

See the javadoc on TraceBaggageConfiguration.baggagePropagationFactoryBuilder()

Related