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?
Asked
Active
Viewed 1,123 times
2
-
1By default it sets the tracing context in separate headers. If you want a single b3 header you have to opt in with a property. So since you've already done it, just disable the property – Marcin Grzejszczak Mar 26 '20 at 14:12
-
I'm using spring-cloud-starter-sleuth 2.2.2.RELEASE and right now the default is a single header. what is the property that i can set to disable it? – neorus Mar 26 '20 at 14:35
-
Actually my bad, we always propagate the multiple headers (https://github.com/spring-cloud/spring-cloud-sleuth/blob/dfcc3223a57dc557c93bbfd983ddc967a56411c3/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/MessageHeaderPropagation.java#L40) . In which field do you see that single B3 header? – Marcin Grzejszczak Mar 26 '20 at 15:11
-
in "properties" on ActiveMQMessage, i see in the following format: b3={123456789abcdefgh-123456789abcdefgh-0} – neorus Mar 27 '20 at 16:44
2 Answers
2
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();
}

Adrian Cole
- 792
- 4
- 10
-
because the default behavior is in a non Spring Boot application(send AMQ messages from Spring Boot to a non Spring Boot), which means sleuth doesn't support it, and i do want to trace in there too. – neorus Mar 28 '20 at 00:23
-
it's not that simple on a legacy code =] yeah the easy solution is just to crop the property, but wanted to avoid doing so – neorus Mar 29 '20 at 06:14
-
This works, but then it ignores any spring.sleuth application.properties you have configured it with. – whistling_marmot Apr 23 '21 at 14:00
-1
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()

whistling_marmot
- 3,561
- 3
- 25
- 39