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.

  • Method Details

    • ofDefault

      public static RequestContextCurrentTraceContext ofDefault()
      Returns the default CurrentTraceContext. Use this when building a Tracing instance for use with BraveService or BraveClient.

      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 a RequestContext 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 a RequestContext.

      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

      @Nullable public @Nullable brave.propagation.TraceContext get()
      Specified by:
      get in class brave.propagation.CurrentTraceContext
    • newScope

      public brave.propagation.CurrentTraceContext.Scope newScope(@Nullable @Nullable brave.propagation.TraceContext currentSpan)
      Specified by:
      newScope in class brave.propagation.CurrentTraceContext
    • decorateScope

      @UnstableApi public brave.propagation.CurrentTraceContext.Scope decorateScope(brave.propagation.TraceContext context, brave.propagation.CurrentTraceContext.Scope scope)
      Overrides:
      decorateScope in class brave.propagation.CurrentTraceContext
    • scopeDecoratorAdded

      @UnstableApi public boolean scopeDecoratorAdded()
      Returns whether this RequestContextCurrentTraceContext is built with CurrentTraceContext.ScopeDecorators.
      See Also: