Prior to Spring Boot 3, tracing, including Kafka tracing, was performed using Sleuth. It was possible to propagate a tracing context (traceId, spanId, baggage) over Kafka.
Sleuth no longer exists. Spring Boot now takes care of these aspects.
It seems that tracing on the producer side (KafkaTemplate) disappeared.
This was previously handled using a template post-processor. See KafkaFactoryBeanPostProcessor, TraceProducerPostProcessor and TracingConsumerPostProcessor for more technical details
Have I forgotten something? Should I configure it manually or import another dependency?
Any comments or feedback are more than welcome on this tricky topic.
EDIT 1:
By adding brave-instrumentation-kafka-clients into the classpath, it's also possible to setup it manually using the following portion of code
@Bean
public <K, V> ProducerFactory<K, V> kafkaProducerFactory(KafkaProperties kafkaProperties, ObjectProvider<Tracing> tracing) {
final var factory = new DefaultKafkaProducerFactory<>(kafkaProperties.buildProducerProperties());
tracing.ifAvailable(t -> {
final var kafkaTracing = KafkaTracing.create(t);
factory.addPostProcessor(kafkaTracing::producer);
});
return factory;
}
The observation is not enabled on Spring Kafka components by default.
See KafkaTemplate.setObservationEnabled(true)
.
More in docs: https://docs.spring.io/spring-kafka/reference/3.1-SNAPSHOT/kafka/micrometer.html#observation