From 41a9d104a83bfcf7ed388daf4724dcd7f68237ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraci=20Paix=C3=A3o=20Kr=C3=B6hling?= Date: Fri, 7 Sep 2018 12:41:18 +0200 Subject: [PATCH] Close tracer on JVM shutdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juraci Paixão Kröhling --- .../main/java/io/jaegertracing/internal/JaegerTracer.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/jaeger-core/src/main/java/io/jaegertracing/internal/JaegerTracer.java b/jaeger-core/src/main/java/io/jaegertracing/internal/JaegerTracer.java index 8d2a62452..c586bbb2c 100644 --- a/jaeger-core/src/main/java/io/jaegertracing/internal/JaegerTracer.java +++ b/jaeger-core/src/main/java/io/jaegertracing/internal/JaegerTracer.java @@ -120,6 +120,14 @@ protected JaegerTracer(JaegerTracer.Builder builder) { } this.ipv4 = ipv4; this.tags = Collections.unmodifiableMap(tags); + + // register this tracer with a shutdown hook, to flush the spans before the VM shuts down + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + JaegerTracer.this.close(); + } + }); } public String getVersion() {