Package brave.propagation
Class StrictScopeDecorator
- java.lang.Object
-
- brave.propagation.StrictScopeDecorator
-
- All Implemented Interfaces:
CurrentTraceContext.ScopeDecorator
,Closeable
,AutoCloseable
public final class StrictScopeDecorator extends Object implements CurrentTraceContext.ScopeDecorator, Closeable
Useful when developing instrumentation as state is enforced more strictly.Ex.
tracing = Tracing.newBuilder() .spanReporter(...) .currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder() .addScopeDecorator(StrictScopeDecorator.create()) .build() ).build();
-
-
Field Summary
-
Fields inherited from interface brave.propagation.CurrentTraceContext.ScopeDecorator
NOOP
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
This is useful in tests to help ensure scopes are not leaked by instrumentation.static StrictScopeDecorator
create()
CurrentTraceContext.Scope
decorateScope(TraceContext context, CurrentTraceContext.Scope scope)
Identifies problems by throwingIllegalStateException
when a scope is closed on a different thread.
-
-
-
Method Detail
-
create
public static StrictScopeDecorator create()
-
decorateScope
public CurrentTraceContext.Scope decorateScope(@Nullable TraceContext context, CurrentTraceContext.Scope scope)
Identifies problems by throwingIllegalStateException
when a scope is closed on a different thread.- Specified by:
decorateScope
in interfaceCurrentTraceContext.ScopeDecorator
- Parameters:
context
- null implies the scope should be clearedscope
-CurrentTraceContext.Scope.NOOP
if the former decoration resulted in no change.
-
close
public void close()
This is useful in tests to help ensure scopes are not leaked by instrumentation.Note: It is important to close all resources prior to calling this, so that in-flight operations are not mistaken as scope leaks. If this raises an error, consider if a wrapped executor is still running.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
AssertionError
- if any scopes were left unclosed.- Since:
- 5.11
-
-