Missing traceId in Kafka listener when consuming in batches
See original GitHub issueTrace info is lost and current span is null when consuming in batches from a KafkaListener.
I’m working with
- Spring Boot 2.3.3
- Spring Kafka 2.5.5
- Spring Cloud Starter Sleuth 2.4.4
I have a listener like
@KafkaListener(topics = "topic")
public void receiveMessage(List<String> messages) {
messages.forEach(log::info);
}
And following property in application.yml:
spring.kafka.listener.type: batch
If I remove the property then traceId is back
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Put trace id for each message in kafka listener - Stack Overflow
How can i use KafkaListenerAnnotationBeanPostProcessor to add trace id for each message coming to the consumer?
Read more >Put trace id for each message in kafka listener-Springboot
Put trace id for each message in kafka listener · Separate Kafka listener for each topic using annotations in spring kafka · Stop...
Read more >Distributed Tracing for Kafka with OpenTelemetry | New Relic
Learn how to implement open source distributed tracing in Kafka with OpenTelemetry and the otelsarama library.
Read more >spring-projects/spring-kafka - Gitter
We consume a message, process it and produce a result, and even sometimes the ... Hi Guys need help on get trace details...
Read more >Spring Cloud Sleuth customization
We decorate the Kafka clients ( KafkaProducer and KafkaConsumer ) to create a span for each event that is produced or consumed. You...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@KostasD21 I was able to repro this issue using your sample project, thanks for that (btw here’s some help for local Kafka).
As I was debugging it, I found that the batch and the non-batch scenarios are handled differently (see: KafkaMessageListenerContainer). This is so different that there are two different components that are calling your
@KafkaListener
.The root cause is that the non-batch listener is decorated by Sleuth, while the batch listener is not. If you stop the execution in
KafkaMessageListenerContainer
where thelistener
or thebatchListener
is used you will see that one of them is proxied, the other one is not (byMessageListenerMethodInterceptor
):This explains why batch does not have traceIds so I looked into where the proxy is set-up: https://github.com/spring-cloud/spring-cloud-sleuth/blob/6b0ceb7ede2a8e3d842be72350c728628d199407/spring-cloud-sleuth-brave/src/main/java/org/springframework/cloud/sleuth/brave/instrument/messaging/SleuthKafkaAspect.java#L105-L109
Unfortunately this scenario is not supported which does make some sense since if there are 10 incoming messages with different traceIDs, which traceId would you pick to propagate to the consumer? If you would like this feature to be implemented, could you please open a new issue as a feature request (please reference this one)?
@Johny-Ch No, currently this is not supported. If there are 10 incoming messages with different traceIDs, which traceId would you pick to propagate to the consumer?