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:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -130,6 +130,11 @@ public interface AssertingSpanBuilder extends Span.Builder {
|
||||
public boolean isStarted() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getDelegate().toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user