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 voidclose()This is useful in tests to help ensure scopes are not leaked by instrumentation.static StrictScopeDecoratorcreate()CurrentTraceContext.ScopedecorateScope(TraceContext context, CurrentTraceContext.Scope scope)Identifies problems by throwingIllegalStateExceptionwhen 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 throwingIllegalStateExceptionwhen a scope is closed on a different thread.- Specified by:
decorateScopein interfaceCurrentTraceContext.ScopeDecorator- Parameters:
context- null implies the scope should be clearedscope-CurrentTraceContext.Scope.NOOPif 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
AssertionError- if any scopes were left unclosed.- Since:
- 5.11
-
-