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

Unregister shutdown hook when tracer is closed #679

Merged
merged 1 commit into from
Jan 8, 2020
Merged
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 @@ -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