Skip to content

Adding doOnSubscribe directly on receiveAutoAck breaks tracing propagation #392

Description

@Thyago

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

  1. Have a tracing agent in place (Eg DataDog)
  2. 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();
    }
}
  1. 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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions