diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxGrpcExporter.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxGrpcExporter.java index 7d029b52fe9e5..270bb82c6fcff 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxGrpcExporter.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxGrpcExporter.java @@ -52,6 +52,7 @@ final class VertxGrpcExporter implements SpanExporter { // We only log unimplemented once since it's a configuration issue that won't be recovered. private final AtomicBoolean loggedUnimplemented = new AtomicBoolean(); private final AtomicBoolean isShutdown = new AtomicBoolean(); + private final CompletableResultCode shutdownResult = new CompletableResultCode(); private final String type; private final ExporterMetrics exporterMetrics; private final SocketAddress server; @@ -145,11 +146,25 @@ public CompletableResultCode flush() { @Override public CompletableResultCode shutdown() { if (!isShutdown.compareAndSet(false, true)) { - logger.log(Level.INFO, "Calling shutdown() multiple times."); - return CompletableResultCode.ofSuccess(); + logger.log(Level.FINE, "Calling shutdown() multiple times."); + return shutdownResult; } - client.close(); - return CompletableResultCode.ofSuccess(); + + client.close() + .onSuccess( + new Handler<>() { + @Override + public void handle(Void event) { + shutdownResult.succeed(); + } + }) + .onFailure(new Handler<>() { + @Override + public void handle(Throwable event) { + shutdownResult.fail(); + } + }); + return shutdownResult; } private static final class ClientRequestOnSuccessHandler implements Handler> { diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxHttpExporter.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxHttpExporter.java index ed09c04c0541a..d3ec075c606d5 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxHttpExporter.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/VertxHttpExporter.java @@ -8,13 +8,17 @@ import java.time.Duration; import java.util.Collection; import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.zip.GZIPOutputStream; import io.opentelemetry.exporter.internal.http.HttpExporter; import io.opentelemetry.exporter.internal.http.HttpSender; import io.opentelemetry.exporter.internal.otlp.traces.TraceRequestMarshaler; import io.opentelemetry.sdk.common.CompletableResultCode; +import io.opentelemetry.sdk.internal.ThrottlingLogger; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.export.SpanExporter; import io.quarkus.vertx.core.runtime.BufferOutputStream; @@ -31,6 +35,9 @@ final class VertxHttpExporter implements SpanExporter { + private static final Logger internalLogger = Logger.getLogger(VertxHttpExporter.class.getName()); + private static final ThrottlingLogger logger = new ThrottlingLogger(internalLogger); + private final HttpExporter delegate; VertxHttpExporter(HttpExporter delegate) { @@ -83,6 +90,9 @@ static final class VertxHttpSender implements HttpSender { this.client = vertx.createHttpClient(httpClientOptions); } + private final AtomicBoolean isShutdown = new AtomicBoolean(); + private final CompletableResultCode shutdownResult = new CompletableResultCode(); + private static String determineBasePath(URI baseUri) { String path = baseUri.getPath(); if (path.isEmpty() || path.equals("/")) { @@ -173,8 +183,26 @@ public byte[] responseBody() { @Override public CompletableResultCode shutdown() { - client.close(); - return CompletableResultCode.ofSuccess(); + if (!isShutdown.compareAndSet(false, true)) { + logger.log(Level.FINE, "Calling shutdown() multiple times."); + return shutdownResult; + } + + client.close() + .onSuccess( + new Handler<>() { + @Override + public void handle(Void event) { + shutdownResult.succeed(); + } + }) + .onFailure(new Handler<>() { + @Override + public void handle(Throwable event) { + shutdownResult.fail(); + } + }); + return shutdownResult; } } }