Spring Boot Kafka Micrometer 可观测性在启用并发的情况下不起作用

问题描述 投票:0回答:1

我将我的应用程序配置为以这种方式加载基于属性的bean:

        @Bean
        @ConditionalOnProperty(
            prefix = "fleexi.kafka.override-concurrency",
            value = {"enabled"}
        )
        ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactoryWithConcurrency(ConsumerFactory<String, String> kafkaConsumerFactory, FleexiKafkaProperties fleexiKafkaProperties) {
            ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory();
            factory.setConcurrency(fleexiKafkaProperties.getOverrideConcurrency().getListenerConcurrency());
            factory.getContainerProperties().setObservationEnabled(true);
            factory.setConsumerFactory(kafkaConsumerFactory);
            return factory;
        }

        @Bean
        @ConditionalOnMissingBean({ConcurrentKafkaListenerContainerFactory.class})
        ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory(ConsumerFactory<String, String> kafkaConsumerFactory) {
            ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory();
            factory.getContainerProperties().setObservationEnabled(true);
            factory.setConsumerFactory(kafkaConsumerFactory);
            return factory;
        }

在第一种情况下,启用并发的可观察性日志traceId和spanId不起作用。

enter image description here

第二种情况,没有并发也能正常工作 enter image description here

并发破坏了可观察性?

编辑: 这里的例子: https://github.com/claudiomerli/demo-issue-spring-kafka-3459

apache-kafka concurrency micrometer observability
1个回答
0
投票

您的问题在这里:

 ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactoryWithConcurrency(

其中

containerFactory
的默认
@KafkaListener
确实是
kafkaListenerContainerFactory

因此,由于您的自定义

kafkaListenerContainerFactoryWithConcurrency
已不再使用,因此未记录跟踪也就不足为奇了。

尝试仅使用此配置属性而不是那些 bean:

spring.kafka.consumer.group-id=TEST
spring.kafka.listener.concurrency=10
spring.kafka.listener.observation-enabled=true
© www.soinside.com 2019 - 2024. All rights reserved.