Skip to content

Commit 59e5a80

Browse files
sobychackoartembilan
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. **Auto-cherry-pick to `3.0.x`** # Conflicts: # spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/ObservationTests.java
1 parent 9bc45c9 commit 59e5a80

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
@@ -770,7 +770,9 @@ private CompletableFuture<SendResult<K, V>> observeSend(final ProducerRecord<K,
770770
this.observationRegistry);
771771
try {
772772
observation.start();
773-
return doSend(producerRecord, observation);
773+
try (Observation.Scope ignored = observation.openScope()) {
774+
return doSend(producerRecord, observation);
775+
}
774776
}
775777
catch (RuntimeException ex) {
776778
// The error is added from org.apache.kafka.clients.producer.Callback

0 commit comments

Comments
 (0)