Class RequestContextCurrentTraceContext
java.lang.Object
brave.propagation.CurrentTraceContext
com.linecorp.armeria.common.brave.RequestContextCurrentTraceContext
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 TypeMethodDescriptionbuilder()
Use this when you need customizations such as log integration via RequestContextCurrentTraceContextBuilder.addScopeDecorator(ScopeDecorator).decorateScope
(TraceContext context, CurrentTraceContext.Scope scope) get()
newScope
(@Nullable TraceContext currentSpan) Returns the defaultCurrentTraceContext
.boolean
Returns whether thisRequestContextCurrentTraceContext
is built withCurrentTraceContext.ScopeDecorator
s.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
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 RequestContextCurrentTraceContextBuilder.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
-
decorateScope
@UnstableApi public CurrentTraceContext.Scope decorateScope(TraceContext context, CurrentTraceContext.Scope scope) - Overrides:
decorateScope
in classCurrentTraceContext
-
scopeDecoratorAdded
Returns whether thisRequestContextCurrentTraceContext
is built withCurrentTraceContext.ScopeDecorator
s.
-