Skip to content

Commit

Permalink
Avoid exporter related exceptions when application has been shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Jun 25, 2024
1 parent f5bc656 commit 39fd819
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ private void failOnClientRequest(int numItems, Throwable t, CompletableResultCod

@Override
public CompletableResultCode export(Collection<SpanData> spans) {
if (isShutdown.get()) {
return CompletableResultCode.ofFailure();
}

TraceRequestMarshaler request = TraceRequestMarshaler.create(spans);

return export(request, spans.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ final class VertxHttpExporter implements SpanExporter {
private static final int MAX_ATTEMPTS = 3;

private final HttpExporter<TraceRequestMarshaler> delegate;
private final AtomicBoolean isShutdown = new AtomicBoolean();

VertxHttpExporter(HttpExporter<TraceRequestMarshaler> delegate) {
this.delegate = delegate;
}

@Override
public CompletableResultCode export(Collection<SpanData> spans) {
if (isShutdown.get()) {
return CompletableResultCode.ofFailure();
}

TraceRequestMarshaler exportRequest = TraceRequestMarshaler.create(spans);
return delegate.export(exportRequest, spans.size());
}
Expand All @@ -62,6 +67,10 @@ public CompletableResultCode flush() {

@Override
public CompletableResultCode shutdown() {
if (!isShutdown.compareAndSet(false, true)) {
logger.log(Level.FINE, "Calling shutdown() multiple times.");
return CompletableResultCode.ofSuccess();
}
return delegate.shutdown();
}

Expand Down Expand Up @@ -95,7 +104,6 @@ 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) {
Expand Down Expand Up @@ -148,11 +156,6 @@ public void accept(HttpClientRequest request) {

@Override
public CompletableResultCode shutdown() {
if (!isShutdown.compareAndSet(false, true)) {
logger.log(Level.FINE, "Calling shutdown() multiple times.");
return shutdownResult;
}

client.close()
.onSuccess(
new Handler<>() {
Expand Down

0 comments on commit 39fd819

Please sign in to comment.