When adding a doOnSubscribe just after the ReactiveKafkaConsumerTemplate receiveAutoAck flux, leads to the loss of tracing context.
This was tested having Datadog Agent running, which injects parent_id and trace_id.
Expected Behavior
Having a simple doOnSubscribe under the ReactiveKafkaConsumerTemplate receiveAutoAck flux should not affect the tracing context.
Actual Behavior
When doOnSubscribe is added, the tracing is lost and no longer logged or propagated by the service.
Steps to Reproduce
- Have a tracing agent in place (Eg DataDog)
- Add a doOnSubscribe after the receiveAutoAck call:
@Service
@RequiredArgsConstructor
@Slf4j
public class EventListener {
private final ReactiveKafkaConsumerTemplate<String, JsonNode> reactiveKafkaConsumerTemplate;
@EventListener(ApplicationStartedEvent.class)
public Disposable eventRunner() {
return reactiveKafkaConsumerTemplate
.receiveAutoAck()
.doOnSubscribe(s -> log.info("Consumer started"))
.flatMap(consumerRecord -> handleEvent(consumerRecord.value(), consumerRecord.headers()))
.onErrorContinue((error, value) -> log.error("Error while consuming", error.getStackTrace()))
.subscribe();
}
}
- Listen to events and check for trace_id propagation
Environment
Behaviour tested on:
- Spring Boot 3.2.5 up to 3.3.2 (Netty)
- Datadog Java Agent 1.34.0 to 1.38.0
- Reactor Kafka: 1.3.22 to 1.3.23
- Java: 21
- OS: Debian 10 (using Azul Zulu image with Java 21 and Debian 10)
When adding a doOnSubscribe just after the ReactiveKafkaConsumerTemplate receiveAutoAck flux, leads to the loss of tracing context.
This was tested having Datadog Agent running, which injects parent_id and trace_id.
Expected Behavior
Having a simple doOnSubscribe under the ReactiveKafkaConsumerTemplate receiveAutoAck flux should not affect the tracing context.
Actual Behavior
When doOnSubscribe is added, the tracing is lost and no longer logged or propagated by the service.
Steps to Reproduce
Environment
Behaviour tested on: