Class ContextScopeManager
- java.lang.Object
-
- nl.talsmasoftware.context.opentracing.ContextScopeManager
-
- All Implemented Interfaces:
ScopeManager,ContextManager<Span>
public class ContextScopeManager extends Object implements ScopeManager, ContextManager<Span>
Our own implementation of the opentracing ScopeManager.Manages opentracing Scope and allows it to be nested within another active scope, taking care to restore the previous value when closing an active scope.
This manager is based on our AbstractThreadLocalContext implementation. Compared to the 'standard' ThreadLocalScopeManager this implementation has the following advantages:
- Close is explicitly idempotent; closing more than once has no additional side-effects
(even when finishOnClose is set to
true). - More predictable behaviour for out-of-order closing of scopes. Although this is explicitly unsupported by the opentracing specification, we think having consistent and predictable behaviour is an advantage.
- Support for
ContextObserver. See https://github.com/opentracing/opentracing-java/issues/334 explicitly wanting this.
Please note that this scope manager is not somehow automatically enabled. You will have to provide an instance to your tracer of choice when initializing it.
The active span that is automatically propagated when using this
opentracing-span-propagationlibrary in combination with the context aware support classes is from the registered ScopeManager from the GlobalTracer.- Since:
- 1.0.6
-
-
Constructor Summary
Constructors Constructor Description ContextScopeManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Scopeactivate(Span span)Scopeactivate(Span span, boolean finishSpanOnClose)Deprecated.This is no longer part of the OpenTracing API as of0.33.0Scopeactive()Deprecated.This is no longer part of the OpenTracing API as of0.33.0SpanactiveSpan()Context<Span>getActiveContext()The currently active context, ornullif no context is active.Context<Span>initializeNewContext(Span value)Initializes a new context for the given Span.StringtoString()
-
-
-
Method Detail
-
activate
@Deprecated public Scope activate(Span span, boolean finishSpanOnClose)
Deprecated.This is no longer part of the OpenTracing API as of0.33.0Makes the given span the new active span.- Parameters:
span- The span to become the active span.finishSpanOnClose- Whether the span should automatically finish when closing the resulting scope.- Returns:
- The new active scope (must be closed from the same thread).
-
activate
public Scope activate(Span span)
- Specified by:
activatein interfaceScopeManager
-
active
@Deprecated public Scope active()
Deprecated.This is no longer part of the OpenTracing API as of0.33.0The currently activeScopecontaining the active span.- Returns:
- the active scope, or
nullif none could be found.
-
activeSpan
public Span activeSpan()
- Specified by:
activeSpanin interfaceScopeManager
-
initializeNewContext
public Context<Span> initializeNewContext(Span value)
Initializes a new context for the given Span.- Specified by:
initializeNewContextin interfaceContextManager<Span>- Parameters:
value- The span to activate.- Returns:
- The new active 'Scope'.
- See Also:
activate(Span)
-
getActiveContext
public Context<Span> getActiveContext()
Description copied from interface:ContextManagerThe currently active context, ornullif no context is active.- Specified by:
getActiveContextin interfaceContextManager<Span>- Returns:
- The active span context (this is identical to the active scope).
-
-