Class TraceContextPropagation

java.lang.Object
com.linecorp.armeria.client.brave.TraceContextPropagation

@UnstableApi public final class TraceContextPropagation extends Object
Manually propagates a TraceContext to a BraveClient.
  • Method Details

    • inject

      @UnstableApi public static Consumer<ClientRequestContext> inject(Supplier<brave.propagation.TraceContext> traceContextSupplier)
      Injects the current TraceContext through ClientBuilder.contextCustomizer(Consumer) or Clients.withContextCustomizer(Consumer). The injected TraceContext will be propagated to BraveClient as a parent Span.

      Basically, a parent TraceContext is automatically propagated to BraveClient if you use BraveService. This method is useful if you want to manually propagate the current TraceContext to BraveClient in non-Armeria server environment.

      
       Tracing threadLocalTracing = ...;
       Tracing requestContextTracing =
           Tracing.newBuilder()
                  .currentTraceContext(RequestContextCurrentTraceContext.ofDefault())
                  .build();
      
       Clients.builder(...)
              .contextCustomizer(TraceContextPropagation.inject(() -> {
                  return threadLocalTracing.currentTraceContext().get();
              })
              .decorator(BraveClient.newDecorator(requestContextTracing))
              .build();