JDBC tracing context not leaking

without this change there were cases (that we didn't test) where the tracing context would leak and pollute other parts of the code (including tests)
with this change we ensure that in case of errors we don't allow any dangling tracing context
This commit is contained in:
Marcin Grzejszczak
2021-05-26 18:05:43 +02:00
parent feeb251f09
commit 12737adb67
11 changed files with 1088 additions and 929 deletions

View File

@@ -18,6 +18,9 @@ package org.springframework.cloud.sleuth;
import java.io.Closeable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Container object for {@link Span} and its corresponding {@link Tracer.SpanInScope}.
*
@@ -26,6 +29,8 @@ import java.io.Closeable;
*/
public class SpanAndScope implements Closeable {
private static final Log log = LogFactory.getLog(SpanAndScope.class);
private final Span span;
private final Tracer.SpanInScope scope;
@@ -50,6 +55,9 @@ public class SpanAndScope implements Closeable {
@Override
public void close() {
if (log.isTraceEnabled()) {
log.trace("Closing span [" + this.span + "]");
}
this.scope.close();
this.span.end();
}

View File

@@ -130,6 +130,11 @@ public interface AssertingSpanBuilder extends Span.Builder {
public boolean isStarted() {
return true;
}
@Override
public String toString() {
return getDelegate().toString();
}
};
}