question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for @KafkaListener annotations

See original GitHub issue

Hello, I´m new with kafka and sleuth. And I´m having some problems on tracing a producer and a consumer over kafka.

I have one microservice that put some messages into a kafka topic, and the same microservice has a consumer, listening the same topic.

The first part is working just fine, but when the listener consume the message, the log shows no traceID, spanID. Everithing is empty.

I´ve enabled the debug for sleuth and at the producer part, I can see lots of debug messages, but at the consumer part, the only thing that was show is the log, without any trace information.

Here is the consumer code:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Service;


@Service
public class Receiver {
    private static final Logger LOG = LoggerFactory.getLogger(Receiver.class);
    
    @Value("${app.topic.topic02}")
    private String topic;

    
    @KafkaListener(topics = "${app.topic.topic02}")
    public void listen(@Payload String message,@Headers MessageHeaders messageHeaders) {
        //System.out.println("received message = " + message + " to topic = " + topic);
    	LOG.info("received message = " + message + " to topic = " + topic);
    }

}

And the Logs with debug enabled:

----> Producer Part

2018-06-05 17:13:22.561 DEBUG [apollo11-referencemicroservice,,,] 15046 --- [tp2067180044-14] o.s.c.sleuth.instrument.web.TraceFilter  : Received a request to uri [/sendMessageToKafka] that should not be sampled [false]
2018-06-05 17:13:22.562 DEBUG [apollo11-referencemicroservice,3071bc3b73453c71,3071bc3b73453c71,true] 15046 --- [tp2067180044-14] o.s.c.sleuth.instrument.web.TraceFilter  : No parent span present - creating a new span
2018-06-05 17:13:22.564 DEBUG [apollo11-referencemicroservice,3071bc3b73453c71,3071bc3b73453c71,true] 15046 --- [tp2067180044-14] o.s.c.s.i.web.TraceHandlerInterceptor    : Handling span [Trace: 3071bc3b73453c71, Span: 3071bc3b73453c71, Parent: null, exportable:true]
2018-06-05 17:13:22.564 DEBUG [apollo11-referencemicroservice,3071bc3b73453c71,3071bc3b73453c71,true] 15046 --- [tp2067180044-14] o.s.c.s.i.web.TraceHandlerInterceptor    : Adding a method tag with value [sendMessageToKafka] to a span [Trace: 3071bc3b73453c71, Span: 3071bc3b73453c71, Parent: null, exportable:true]
2018-06-05 17:13:22.564 DEBUG [apollo11-referencemicroservice,3071bc3b73453c71,3071bc3b73453c71,true] 15046 --- [tp2067180044-14] o.s.c.s.i.web.TraceHandlerInterceptor    : Adding a class tag with value [Application] to a span [Trace: 3071bc3b73453c71, Span: 3071bc3b73453c71, Parent: null, exportable:true]
2018-06-05 17:13:22.567 DEBUG [apollo11-referencemicroservice,3071bc3b73453c71,3071bc3b73453c71,true] 15046 --- [-KafkaService-2] ConcurrencyStrategy$HystrixTraceCallable : Continuing span [Trace: 3071bc3b73453c71, Span: 3071bc3b73453c71, Parent: null, exportable:true]
2018-06-05 17:13:22.568  INFO [apollo11-referencemicroservice,3071bc3b73453c71,3071bc3b73453c71,true] 15046 --- [-KafkaService-2] b.com.b3.apollo11.kafka.producer.Sender  : Trying to send message to Kafka:
{"prazo":"LONGO","objetivo":"APTO","perfilInvestidor":"SABER_VALOR_FINAL","formaRemuneracao":"FINAL_INVESTIMENRO","uuid":"123e4567-e89b-12d3-a456-426655440000"}
2018-06-05 17:13:22.568  INFO [apollo11-referencemicroservice,3071bc3b73453c71,3071bc3b73453c71,true] 15046 --- [-KafkaService-2] b.com.b3.apollo11.kafka.producer.Sender  : sending message = {"prazo":"LONGO","objetivo":"APTO","perfilInvestidor":"SABER_VALOR_FINAL","formaRemuneracao":"FINAL_INVESTIMENRO","uuid":"123e4567-e89b-12d3-a456-426655440000"} to topic = operationA
2018-06-05 17:13:22.569 DEBUG [apollo11-referencemicroservice,3071bc3b73453c71,3071bc3b73453c71,true] 15046 --- [-KafkaService-2] ConcurrencyStrategy$HystrixTraceCallable : Detaching span since it was continued [Trace: 3071bc3b73453c71, Span: 3071bc3b73453c71, Parent: null, exportable:true]
2018-06-05 17:13:22.571 DEBUG [apollo11-referencemicroservice,3071bc3b73453c71,3071bc3b73453c71,true] 15046 --- [tp2067180044-14] o.s.c.sleuth.instrument.web.TraceFilter  : Closing the span [Trace: 3071bc3b73453c71, Span: 3071bc3b73453c71, Parent: null, exportable:true] since the response was successful
2018-06-05 17:13:22.572 DEBUG [apollo11-referencemicroservice,3071bc3b73453c71,3071bc3b73453c71,true] 15046 --- [tp2067180044-14] o.s.c.s.zipkin2.DefaultEndpointLocator   : Span will contain serviceName [apollo11-referencemicroservice]

----> Consumer Part

2018-06-05 17:13:22.575  INFO **[apollo11-referencemicroservice,,,]** 15046 --- [ntainer#0-0-C-1] b.c.b3.apollo11.kafka.consumer.Receiver  : received message = {"prazo":"LONGO","objetivo":"APTO","perfilInvestidor":"SABER_VALOR_FINAL","formaRemuneracao":"FINAL_INVESTIMENRO","uuid":"123e4567-e89b-12d3-a456-426655440000"} to topic = operationA

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
timtebeekcommented, Aug 18, 2018

Hi! Seems this issue went off-course with unrelated issues for a moment; coming back on topic I would also like to use plain @KafkaListener annotations whilst propagating trace/span data from my producers. This issue seems to indicate that’s not (yet) possible, but in my sample project here the tests seem to indicate it works: https://github.com/timtebeek/sleuth-kafkalistener

Now I’m puzzled; can anyone either confirm this works, or point out the flaw in my example project? If there’s documentation to be updated that would also be helpful, although I wouldn’t really know what to add or where. Any help appreciated. 😃

1reaction
fsopjanicommented, Jun 26, 2018

@danielsouza85 Remove your sensitive info in your application.properties, you’ve got host, passwords everything on the configuration properties exposed to public unnecessary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

KafkaListener (Spring for Apache Kafka 3.0.0 API)
Annotation that marks a method to be the target of a Kafka message listener on the specified topics. The containerFactory() identifies the ...
Read more >
@KafkaListener | Spring Boot Example - StackChief
The @KafkaListener is an annotation that marks a method or class as the target of incoming messages. By using @KafkaListener, you abstract away ......
Read more >
Intro to Apache Kafka with Spring - Baeldung
In this tutorial, we'll cover Spring support for Kafka and the level of ... and Message-driven POJOs via @KafkaListener annotation.
Read more >
Create meta-annotation for @KafkaListener - Stack Overflow
But it does not work. Am I doing something wrong or is Spring-kafka just not supporting @AliasFor annotations for @KafkaListener? Please help.
Read more >
Learn to Consume Messages with KafkaListener
First, create a new Consumer class with a method consume and an annotation with the topic that you'd like to listen to, as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found