From ee859f46e42009e1c6b8b703da3a5c3c9f3c3119 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Cortez Date: Sat, 18 Jan 2020 01:32:43 -0600 Subject: [PATCH] Log an error when Scope.close() is called on the incorrect object. --- .../main/java/io/opentracing/util/ThreadLocalScope.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/opentracing-util/src/main/java/io/opentracing/util/ThreadLocalScope.java b/opentracing-util/src/main/java/io/opentracing/util/ThreadLocalScope.java index 65b3f8f9..bffb1b65 100644 --- a/opentracing-util/src/main/java/io/opentracing/util/ThreadLocalScope.java +++ b/opentracing-util/src/main/java/io/opentracing/util/ThreadLocalScope.java @@ -17,6 +17,9 @@ import io.opentracing.ScopeManager; import io.opentracing.Span; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * {@link ThreadLocalScope} is a simple {@link Scope} implementation that relies on Java's * thread-local storage primitive. @@ -24,6 +27,8 @@ * @see ScopeManager */ public class ThreadLocalScope implements Scope { + private static final Logger log = Logger.getLogger(ThreadLocalScope.class.getName()); + private final ThreadLocalScopeManager scopeManager; private final Span wrapped; private final ThreadLocalScope toRestore; @@ -39,6 +44,8 @@ public class ThreadLocalScope implements Scope { public void close() { if (scopeManager.tlsScope.get() != this) { // This shouldn't happen if users call methods in the expected order. Bail out. + log.log(Level.SEVERE, "Scope being closed is not the active instance.", + new Throwable().fillInStackTrace()); return; }