Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ private ProducerRecord<K, V> interceptorProducerRecord(ProducerRecord<K, V> prod
return producerRecord;
}

@SuppressWarnings("try")
private Callback buildCallback(final ProducerRecord<K, V> producerRecord, final Producer<K, V> producer,
final CompletableFuture<SendResult<K, V>> future, @Nullable Object sample, Observation observation) {

Expand All @@ -841,10 +842,9 @@ private Callback buildCallback(final ProducerRecord<K, V> producerRecord, final
catch (Exception e) {
this.logger.warn(e, () -> "Error executing interceptor onAcknowledgement callback");
}
try {
try (Observation.Scope ignored = observation.openScope()) {
if (exception == null) {
successTimer(sample, producerRecord);
observation.stop();
future.complete(new SendResult<>(producerRecord, metadata));
if (this.producerListener != null) {
this.producerListener.onSuccess(producerRecord, metadata);
Expand All @@ -855,7 +855,6 @@ private Callback buildCallback(final ProducerRecord<K, V> producerRecord, final
else {
failureTimer(sample, exception, producerRecord);
observation.error(exception);
observation.stop();
future.completeExceptionally(
new KafkaProducerException(producerRecord, "Failed to send", exception));
if (this.producerListener != null) {
Expand All @@ -865,6 +864,7 @@ private Callback buildCallback(final ProducerRecord<K, V> producerRecord, final
}
}
finally {
observation.stop();
closeProducer(producer, this.transactional);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.consumer.ConsumerConfig;
Expand Down Expand Up @@ -108,7 +109,14 @@ void endToEnd(@Autowired Listener listener, @Autowired KafkaTemplate<Integer, St
@Autowired Config config)
throws InterruptedException, ExecutionException, TimeoutException {

template.send("observation.testT1", "test").get(10, TimeUnit.SECONDS);
AtomicReference<SimpleSpan> spanFromCallback = new AtomicReference<>();

template.send("observation.testT1", "test")
.thenAccept((sendResult) -> spanFromCallback.set(tracer.currentSpan()))
.get(10, TimeUnit.SECONDS);

assertThat(spanFromCallback.get()).isNotNull();

assertThat(listener.latch1.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(listener.record).isNotNull();
Headers headers = listener.record.headers();
Expand Down