Micrometer / Spring Boot 3+ / While method is @ASYNC cant trace on log level

104 Views Asked by At

I have Project which is sending getting events through kafka ı have notticed when ı started to use @Async on EndPoints or any other Event producer methods.Can not see the micrometer tracing logs.Do you have any solutions or recommendations about that ?

private final KafkaTemplate<String, Object> kafkaTemplate;
private final KafkaProperties kafkaProperties;

@Async//PROBLEM CHILD.....
public void sendResetPasswordEmail(ResetPasswordEmailEvent resetPasswordEmailEvent) {   
kafkaTemplate.send(kafkaProperties.getTopic().getResetPasswordEmail(),resetPasswordEmailEvent);

    log.info("Reset password email sent: {} ", resetPasswordEmailEvent.toString());
}

and my kafkaTemplate Config is right below

@RequiredArgsConstructor
@Configuration
public class ProducerConfiguration {

    private final KafkaProperties kafkaProperties;

    @Bean
    public ProducerFactory<String, Object> producerFactory() {
        Map<String, Object> configProps = new HashMap<>();
        configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaProperties.getAddress());
        configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
        configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
        
        return new DefaultKafkaProducerFactory<>(configProps);
    }

    @Bean
    public KafkaTemplate<String, Object> kafkaTemplate() {

        KafkaTemplate<String, Object> kafkaTemplate = new KafkaTemplate<>(producerFactory());
        kafkaTemplate.setMicrometerEnabled(true);
        kafkaTemplate.setObservationEnabled(true);

        return kafkaTemplate;
    }
}

When I dont use @Async everything is fine and trace,spanId's created on log.After using @ASYNC any other method trace , spandId's cant able to trace on logs.(all ı saw on the log at this case [ , ] )

Checked my pom and producer , consumer as well everything is fine except @ASYNC....

0

There are 0 best solutions below