From 251b6545d072335575750088b4eb750197be9ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Willi=20Sch=C3=B6nborn?= Date: Tue, 26 Nov 2019 20:14:54 +0100 Subject: [PATCH] Added try-finally to span finish --- .../jdbc/TracingQueryExecutionListener.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/opentracing-jdbc/opentracing-jdbc/src/main/java/org/zalando/opentracing/jdbc/TracingQueryExecutionListener.java b/opentracing-jdbc/opentracing-jdbc/src/main/java/org/zalando/opentracing/jdbc/TracingQueryExecutionListener.java index 47e6033c..85e1059a 100644 --- a/opentracing-jdbc/opentracing-jdbc/src/main/java/org/zalando/opentracing/jdbc/TracingQueryExecutionListener.java +++ b/opentracing-jdbc/opentracing-jdbc/src/main/java/org/zalando/opentracing/jdbc/TracingQueryExecutionListener.java @@ -48,14 +48,16 @@ public void beforeQuery(final ExecutionInfo info, final List infos) { public void afterQuery(final ExecutionInfo info, final List queries) { final Span span = info.getCustomValue(SPAN, Span.class); - if (!info.isSuccess()) { - final Statement statement = info.getStatement(); - final Throwable error = info.getThrowable(); - - decorator.onError(span, statement, error); + try { + if (!info.isSuccess()) { + final Statement statement = info.getStatement(); + final Throwable error = info.getThrowable(); + + decorator.onError(span, statement, error); + } + } finally { + span.finish(); } - - span.finish(); } }