Skip to content

Commit

Permalink
GH-3210: KafkaTemplate currentSpan tagging issue
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sobychacko authored and artembilan committed Apr 23, 2024
1 parent 9bc45c9 commit 59e5a80
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,9 @@ private CompletableFuture<SendResult<K, V>> observeSend(final ProducerRecord<K,
this.observationRegistry);
try {
observation.start();
return doSend(producerRecord, observation);
try (Observation.Scope ignored = observation.openScope()) {
return doSend(producerRecord, observation);
}
}
catch (RuntimeException ex) {
// The error is added from org.apache.kafka.clients.producer.Callback
Expand Down

0 comments on commit 59e5a80

Please sign in to comment.