-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
NoOpTraceContext,TraceContextImpl
public interface TraceContext extends AutoCloseable
TheTraceContextrepresents a certain area of code, like a method. Contexts can be nested. Each context has a rootTracethat can be further divided into sub-traces.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidclose()Closes this trace context.ActiveTracegetActiveTrace()Returns the deepest currently active trace of the current context or a no-op dummy if none is available.UUIDgetId()booleanisRootContext()Trace contexts can be nested.voidsetExitThrowable(Throwable exitThrowable)Setting a throwable indicates that the trace context hasn't exited regularly.default ActiveTracestartTrace(String label)Starts a new sub-trace as a direct child of this trace context.ActiveTracestartTrace(String label, Object... labelFormatArgs)Starts a new sub-trace within this trace context.
-
-
-
Method Detail
-
getId
UUID getId()
-
isRootContext
boolean isRootContext()
Trace contexts can be nested. This method returns whether this is the root context.- Returns:
- whether this is the root context
-
setExitThrowable
void setExitThrowable(Throwable exitThrowable)
Setting a throwable indicates that the trace context hasn't exited regularly. As a consequence, durations can't necessarily be compared to other traces.- Parameters:
exitThrowable- the throwable that exited the trace
-
startTrace
default ActiveTrace startTrace(String label)
Starts a new sub-trace as a direct child of this trace context. Ends any currently active trace of this context, if there is one.This method returns an
ActiveTracethat can be used in a try-with-resource.- Parameters:
label- the label to use for this trace- Returns:
- an
ActiveTracethat can be used in a try-with-resource
-
startTrace
ActiveTrace startTrace(String label, Object... labelFormatArgs)
Starts a new sub-trace within this trace context. Ends the currently active trace of this trace context, if there is one.v *
- Parameters:
label- the label to use for this trace; may contain placeholderslabelFormatArgs- the format arguments for the placeholders in the label- Returns:
- an
ActiveTracethat can be used in a try-with-resource
-
getActiveTrace
ActiveTrace getActiveTrace()
Returns the deepest currently active trace of the current context or a no-op dummy if none is available.- Returns:
- the deepest currently active trace of the current context or a no-op dummy if none is available.
-
close
void close()
Closes this trace context. Closing a trace context is the responsibility of the one opening it.Overridden from
AutoCloseable.close()to remove thrownException.- Specified by:
closein interfaceAutoCloseable
-
-