Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Unregister shutdown hook when tracer is closed (#679)
Browse files Browse the repository at this point in the history
Resolves #677

Signed-off-by: Tomas Hofman <thofman@redhat.com>
  • Loading branch information
TomasHofman authored and pavolloffay committed Jan 8, 2020
1 parent 7e1a618 commit 4bde959
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class JaegerTracer implements Tracer, Closeable {
@ToString.Exclude private final BaggageSetter baggageSetter;
@ToString.Exclude private final JaegerObjectFactory objectFactory;
@ToString.Exclude private final int ipv4; // human readable representation is present within the tag map
@ToString.Exclude private Thread shutdownHook;

protected JaegerTracer(JaegerTracer.Builder builder) {
this.serviceName = builder.serviceName;
Expand Down Expand Up @@ -129,12 +130,13 @@ protected JaegerTracer(JaegerTracer.Builder builder) {
log.info("No shutdown hook registered: Please call close() manually on application shutdown.");
} else {
// register this tracer with a shutdown hook, to flush the spans before the VM shuts down
Runtime.getRuntime().addShutdownHook(new Thread() {
shutdownHook = new Thread() {
@Override
public void run() {
JaegerTracer.this.close();
}
});
};
Runtime.getRuntime().addShutdownHook(shutdownHook);
}
}

Expand Down Expand Up @@ -224,6 +226,9 @@ public <T> JaegerSpanContext extract(Format<T> format, T carrier) {
public void close() {
reporter.close();
sampler.close();
if (shutdownHook != null) {
Runtime.getRuntime().removeShutdownHook(shutdownHook);
}
}

public class SpanBuilder implements Tracer.SpanBuilder {
Expand Down

0 comments on commit 4bde959

Please sign in to comment.