Package io.opencensus.trace
Class CurrentSpanUtils
- java.lang.Object
-
- io.opencensus.trace.CurrentSpanUtils
-
final class CurrentSpanUtils extends java.lang.ObjectUtil methods/functionality to interact with theSpanin theContext.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classCurrentSpanUtils.CallableInSpan<V>private static classCurrentSpanUtils.RunnableInSpanprivate static classCurrentSpanUtils.ScopeInSpan
-
Constructor Summary
Constructors Modifier Constructor Description privateCurrentSpanUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static SpangetCurrentSpan()Returns TheSpanfrom the current context.private static voidsetErrorStatus(Span span, java.lang.Throwable t)(package private) static ScopewithSpan(Span span, boolean endSpan)Enters the scope of code where the givenSpanis in the current context, and returns an object that represents that scope.(package private) static java.lang.RunnablewithSpan(Span span, boolean endSpan, java.lang.Runnable runnable)Wraps aRunnableso that it executes with thespanas the currentSpan.(package private) static <C> java.util.concurrent.Callable<C>withSpan(Span span, boolean endSpan, java.util.concurrent.Callable<C> callable)Wraps aCallableso that it executes with thespanas the currentSpan.
-
-
-
Method Detail
-
getCurrentSpan
@Nullable static Span getCurrentSpan()
Returns TheSpanfrom the current context.- Returns:
- The
Spanfrom the current context.
-
withSpan
static Scope withSpan(Span span, boolean endSpan)
Enters the scope of code where the givenSpanis 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- TheSpanto be set to the current context.endSpan- iftruethe returnedScopewill close theSpan.- Returns:
- An object that defines a scope where the given
Spanis set to the current context.
-
withSpan
static java.lang.Runnable withSpan(Span span, boolean endSpan, java.lang.Runnable runnable)
Wraps aRunnableso that it executes with thespanas the currentSpan.- Parameters:
span- theSpanto be set as current.endSpan- iftruethe returnedRunnablewill close theSpan.runnable- theRunnableto run in theSpan.- Returns:
- the wrapped
Runnable.
-
withSpan
static <C> java.util.concurrent.Callable<C> withSpan(Span span, boolean endSpan, java.util.concurrent.Callable<C> callable)
Wraps aCallableso that it executes with thespanas the currentSpan.- Parameters:
span- theSpanto be set as current.endSpan- iftruethe returnedRunnablewill close theSpan.callable- theCallableto run in theSpan.- Returns:
- the wrapped
Callable.
-
setErrorStatus
private static void setErrorStatus(Span span, java.lang.Throwable t)
-
-