Class RequestContextCurrentTraceContext
java.lang.Object
brave.propagation.CurrentTraceContext
com.linecorp.armeria.common.brave.RequestContextCurrentTraceContext
public final class RequestContextCurrentTraceContext
extends brave.propagation.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
brave.propagation.CurrentTraceContext.Builder, brave.propagation.CurrentTraceContext.Default, brave.propagation.CurrentTraceContext.Scope, brave.propagation.CurrentTraceContext.ScopeDecorator
-
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Use this when you need customizations such as log integration via RequestContextCurrentTraceContextBuilder.addScopeDecorator(ScopeDecorator).brave.propagation.CurrentTraceContext.Scope
decorateScope
(brave.propagation.TraceContext context, brave.propagation.CurrentTraceContext.Scope scope) @Nullable brave.propagation.TraceContext
get()
brave.propagation.CurrentTraceContext.Scope
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.- See Also:
-
Tracing.Builder.currentTraceContext(CurrentTraceContext)
-
builder
Use this when you need customizations such as log integration via RequestContextCurrentTraceContextBuilder.addScopeDecorator(ScopeDecorator).- See Also:
-
Tracing.Builder.currentTraceContext(CurrentTraceContext)
-
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 classbrave.propagation.CurrentTraceContext
-
newScope
public brave.propagation.CurrentTraceContext.Scope newScope(@Nullable @Nullable brave.propagation.TraceContext currentSpan) - Specified by:
newScope
in classbrave.propagation.CurrentTraceContext
-
decorateScope
@UnstableApi public brave.propagation.CurrentTraceContext.Scope decorateScope(brave.propagation.TraceContext context, brave.propagation.CurrentTraceContext.Scope scope) - Overrides:
decorateScope
in classbrave.propagation.CurrentTraceContext
-
scopeDecoratorAdded
Returns whether thisRequestContextCurrentTraceContext
is built withCurrentTraceContext.ScopeDecorator
s.
-