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(); } }