From 5726123f94c2fc8a4fec8a02c2a8a300a1156d47 Mon Sep 17 00:00:00 2001 From: Christian Fredriksson <50839054+cfredri4@users.noreply.github.com> Date: Wed, 5 Mar 2025 15:06:43 +0100 Subject: [PATCH] GH-3779: Fix KafkaTemplate from hiding error when starting observation Fixes: #3779 This fixes that exceptions thrown from `observation.start()` are hidden by `KafkaTemplate` throwing a new exception due to registering observation error without successfully starting the observation. Signed-off-by: Christian Fredriksson (cherry picked from commit bdd1fd3556e69ae20dfc72d66f6c5ead641cfb6c) --- .../main/java/org/springframework/kafka/core/KafkaTemplate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-kafka/src/main/java/org/springframework/kafka/core/KafkaTemplate.java b/spring-kafka/src/main/java/org/springframework/kafka/core/KafkaTemplate.java index 14caa930..691bd40c 100644 --- a/spring-kafka/src/main/java/org/springframework/kafka/core/KafkaTemplate.java +++ b/spring-kafka/src/main/java/org/springframework/kafka/core/KafkaTemplate.java @@ -799,8 +799,8 @@ public class KafkaTemplate implements KafkaOperations, ApplicationCo this.observationConvention, DefaultKafkaTemplateObservationConvention.INSTANCE, () -> new KafkaRecordSenderContext(producerRecord, this.beanName, this::clusterId), this.observationRegistry); + observation.start(); try { - observation.start(); try (Observation.Scope ignored = observation.openScope()) { return doSend(producerRecord, observation); }