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.

No elegant way to get span in Kafka ErrorHandler

See original GitHub issue

I need a way to get span in Kafka ErrorHanlder. I do the next thing in error handler -

    @Override
      public void handle(Exception ex, ConsumerRecord<?, ?> consumerRecord) {
        var curSpan = this.kafkaTracing.nextSpan(consumerRecord).name("on-message").start()
       try (Tracer.SpanInScope ws = tracer.withSpanInScope(curSpan)) {
      log.error(ex);
        } finally {
      span.finish();
    }
  }

But method in KafkaTracing nextSpan() - clear all headers before error handler do its job. And KafkaTracing if final and i can’t inherit from it. I have a question - is it a bug that you don’t give an opportunity not to remove headers from ConsumerRecord?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jfumardcommented, Dec 13, 2019

Same problem here ! It seems that the ConsumerRecord<?,?> received in the @Override public void handle(Exception ex, ConsumerRecord<?, ?> consumerRecord) method has been stripped from its headers, including the traceId.

1reaction
AntonKuzValidcommented, Dec 4, 2019

Probably you can add a ThreadLocal, this will be setted in proxy. example -

@Aspect
@Component
public class KafkaTracingAspect {
  /** Текущий Span потока */
  public static final ThreadLocal<Span> currentSpan = new ThreadLocal<>();

  @Autowired private Tracer tracer;

  @Around("@annotation(org.springframework.kafka.annotation.KafkaListener)")
  public Object kafkaListener(ProceedingJoinPoint joinPoint) throws Throwable {
    currentSpan.set(tracer.currentSpan());
    return joinPoint.proceed();
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Stack Overflow
Currently I've faced with an issue, span creates in MessageListenerMethodInterceptor which triggers on KafkaListener, but in case of exception ...
Read more >
Error Handling Patterns in Kafka - Confluent
And in the world of distributed systems, what can go wrong often goes wrong. This blog post covers different ways to handle errors...
Read more >
Spring for Apache Kafka
The simplest way to get started is to use start.spring.io (or the wizards in Spring Tool Suits and Intellij IDEA) and create a...
Read more >
Documentation - Apache Kafka
This tutorial assumes you are starting fresh and have no existing Kafka or ZooKeeper data. Since Kafka console scripts are different for Unix-based...
Read more >
std::span in C++20: Bounds-Safe Views for Sequences of ...
The following program shows how a subspan can be used to modify the referenced objects from a std::vector. // spanTransform.cpp #include < ...
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