Class RequestContextCurrentTraceContext
java.lang.Object
brave.propagation.CurrentTraceContext
com.linecorp.armeria.common.brave.RequestContextCurrentTraceContext
public final class RequestContextCurrentTraceContext extends CurrentTraceContext
Tracing
context implemented with
RequestContext
.
This CurrentTraceContext
stores/loads the trace context into/from a
RequestContext
's attribute so that there's no need for thread local variables
which can lead to unpredictable behavior in asynchronous programming.
-
Nested Class Summary
Nested classes/interfaces inherited from class brave.propagation.CurrentTraceContext
CurrentTraceContext.Builder, CurrentTraceContext.Default, CurrentTraceContext.Scope, CurrentTraceContext.ScopeDecorator
-
Method Summary
Modifier and Type Method Description static RequestContextCurrentTraceContextBuilder
builder()
Use this when you need customizations such as log integration via CurrentTraceContext.Builder.addScopeDecorator(ScopeDecorator).TraceContext
get()
CurrentTraceContext.Scope
newScope(TraceContext currentSpan)
static RequestContextCurrentTraceContext
ofDefault()
Returns the defaultCurrentTraceContext
.static void
setCurrentThreadNotRequestThread(boolean value)
Sets whether the current thread is not a request thread, meaning it is never executed in the scope of a server or client request and will never have aRequestContext
available.Methods inherited from class brave.propagation.CurrentTraceContext
decorateScope, executor, executorService, maybeScope, wrap, wrap
-
Method Details
-
ofDefault
Returns the defaultCurrentTraceContext
. Use this when building aTracing
instance for use withBraveService
orBraveClient
.If you need to customize the context, use
builder()
instead. -
builder
Use this when you need customizations such as log integration via CurrentTraceContext.Builder.addScopeDecorator(ScopeDecorator). -
setCurrentThreadNotRequestThread
public static void setCurrentThreadNotRequestThread(boolean value)Sets whether the current thread is not a request thread, meaning it is never executed in the scope of a server or client request and will never have aRequestContext
available. This can be called from background threads, such as the thread that reports traced spans to storage, to prevent logging a warning when trying to start a trace without having aRequestContext
.For example, you could prevent warnings from the administrative threads controlled by a
ThreadFactory
like the following:> ThreadFactory factory = (runnable) -> new Thread(new Runnable() { > @Override > public void run() { > RequestContextCurrentTraceContext.setCurrentThreadNotRequestThread(true); > runnable.run(); > } > > @Override > public String toString() { > return runnable.toString(); > } > });
-
get
- Specified by:
get
in classCurrentTraceContext
-
newScope
- Specified by:
newScope
in classCurrentTraceContext
-