Class CurrentSpanUtils

java.lang.Object
io.opencensus.trace.CurrentSpanUtils

final class CurrentSpanUtils extends Object
Util methods/functionality to interact with the Span in the Context.
  • Constructor Details

    • CurrentSpanUtils

      private CurrentSpanUtils()
  • Method Details

    • getCurrentSpan

      @Nullable static Span getCurrentSpan()
      Returns The Span from the current context.
      Returns:
      The Span from the current context.
    • withSpan

      static Scope withSpan(Span span, boolean endSpan)
      Enters the scope of code where the given Span is in the current context, and returns an object that represents that scope. The scope is exited when the returned object is closed.

      Supports try-with-resource idiom.

      Parameters:
      span - The Span to be set to the current context.
      endSpan - if true the returned Scope will close the Span.
      Returns:
      An object that defines a scope where the given Span is set to the current context.
    • withSpan

      static Runnable withSpan(Span span, boolean endSpan, Runnable runnable)
      Wraps a Runnable so that it executes with the span as the current Span.
      Parameters:
      span - the Span to be set as current.
      endSpan - if true the returned Runnable will close the Span.
      runnable - the Runnable to run in the Span.
      Returns:
      the wrapped Runnable.
    • withSpan

      static <C> Callable<C> withSpan(Span span, boolean endSpan, Callable<C> callable)
      Wraps a Callable so that it executes with the span as the current Span.
      Parameters:
      span - the Span to be set as current.
      endSpan - if true the returned Runnable will close the Span.
      callable - the Callable to run in the Span.
      Returns:
      the wrapped Callable.
    • setErrorStatus

      private static void setErrorStatus(Span span, Throwable t)