Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit ee859f4

Browse files
committed
Log an error when Scope.close() is called on the incorrect object.
1 parent d74e467 commit ee859f4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

opentracing-util/src/main/java/io/opentracing/util/ThreadLocalScope.java

+7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@
1717
import io.opentracing.ScopeManager;
1818
import io.opentracing.Span;
1919

20+
import java.util.logging.Level;
21+
import java.util.logging.Logger;
22+
2023
/**
2124
* {@link ThreadLocalScope} is a simple {@link Scope} implementation that relies on Java's
2225
* thread-local storage primitive.
2326
*
2427
* @see ScopeManager
2528
*/
2629
public class ThreadLocalScope implements Scope {
30+
private static final Logger log = Logger.getLogger(ThreadLocalScope.class.getName());
31+
2732
private final ThreadLocalScopeManager scopeManager;
2833
private final Span wrapped;
2934
private final ThreadLocalScope toRestore;
@@ -39,6 +44,8 @@ public class ThreadLocalScope implements Scope {
3944
public void close() {
4045
if (scopeManager.tlsScope.get() != this) {
4146
// This shouldn't happen if users call methods in the expected order. Bail out.
47+
log.log(Level.SEVERE, "Scope being closed is not the active instance.",
48+
new Throwable().fillInStackTrace());
4249
return;
4350
}
4451

0 commit comments

Comments
 (0)