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
-
Method Summary
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 Details
-
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
-