Skip to content

Commit ac7911c

Browse files
sobychackospring-builds
authored andcommitted
GH-3210: KafkaTemplate currentSpan tagging issue
Fixes: #3210 * When adding a tag to the current span during the sending of a kafka message using KafkaTemplate, the tag gets added to another span because KafkaTemplate doesn't open the scope for the started observation. Fixing this issue by wrapping the doSend method call in a proper observation scope. # Conflicts: # spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/ObservationTests.java (cherry picked from commit 59e5a80)
1 parent d244661 commit ac7911c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

spring-kafka/src/main/java/org/springframework/kafka/core/KafkaTemplate.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,9 @@ private CompletableFuture<SendResult<K, V>> observeSend(final ProducerRecord<K,
768768
this.observationRegistry);
769769
try {
770770
observation.start();
771-
return doSend(producerRecord, observation);
771+
try (Observation.Scope ignored = observation.openScope()) {
772+
return doSend(producerRecord, observation);
773+
}
772774
}
773775
catch (RuntimeException ex) {
774776
// The error is added from org.apache.kafka.clients.producer.Callback

0 commit comments

Comments
 (0)