Skip to content

KafkaTemplate is reporting 2 errors to observation on immediate errors (one in callback and one in catched exception from the same callback) #2817

Closed
@BartoszSta

Description

@BartoszSta

In what version(s) of Spring for Apache Kafka are you seeing this issue?

3.0.7

Describe the bug

When KafkaTemplate sends message which immediately fails (for example because of TopicAuthorizationException) then it will report two exceptions to observation:

  • one in callback,
  • one in catched exception which is thrown in doSend() method after checking that (sendFuture.isDone()) - original exception is then wrapped with KafkaException and thrown (throw new KafkaException("Send failed", e.getCause())) - this exception is then caught in observeSend method and reported to observation again (but this time wrapped KafkaException is reported)

So now after such 1 failure I see two metric counters increased, one with original exception for example TopicAuthorizationException and another with KafkaException which is not perfect because I had just one fail.

To Reproduce

It is easy to reproduce by sending message to wrongly named topic, assuming auto create topics is possible on kafka:

kafkaTemplate.send("wrong%Topic", "data")

This will cause 2 counters increased: one for InvalidTopicException and KafkaException.

Expected behavior

Only one error (Exception) is reported to observation which results in just one counter increased.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions