Class 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:

    1. Close is explicitly idempotent; closing more than once has no additional side-effects (even when finishOnClose is set to true).
    2. 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.
    3. 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-propagation library in combination with the context aware support classes is from the registered ScopeManager from the GlobalTracer.

    Since:
    1.0.6
    • Constructor Detail

      • ContextScopeManager

        public ContextScopeManager()
    • Method Detail

      • activate

        @Deprecated
        public Scope activate​(Span span,
                              boolean finishSpanOnClose)
        Deprecated.
        This is no longer part of the OpenTracing API as of 0.33.0
        Makes 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).
      • active

        @Deprecated
        public Scope active()
        Deprecated.
        This is no longer part of the OpenTracing API as of 0.33.0
        The currently active Scope containing the active span.
        Returns:
        the active scope, or null if none could be found.
      • getActiveContext

        public Context<Span> getActiveContext()
        Description copied from interface: ContextManager
        The currently active context, or null if no context is active.
        Specified by:
        getActiveContext in interface ContextManager<Span>
        Returns:
        The active span context (this is identical to the active scope).
      • toString

        public String toString()
        Overrides:
        toString in class Object
        Returns:
        String representation for this context manager.