Class FeignTraceRequestInterceptor

java.lang.Object
com.fayupable.logged.spring.http.FeignTraceRequestInterceptor
All Implemented Interfaces:
feign.RequestInterceptor

public final class FeignTraceRequestInterceptor extends Object implements feign.RequestInterceptor
Feign RequestInterceptor that writes the current @Logged call chain's trace id and depth into an outgoing Feign client request's headers, via HttpTraceHeaderCarrier.

Feign clients are purely synchronous/blocking, exactly like RestTemplate: there is no ambiguity about which thread's FlowContext is captured, since it is always the thread that made the Feign call.

Register this as a Spring bean; Spring Cloud OpenFeign auto-detects any RequestInterceptor bean and applies it to every Feign client in the application:


 @Bean
 public RequestInterceptor loggedTraceRequestInterceptor() {
     return new FeignTraceRequestInterceptor();
 }
 

Not wired in automatically by this library itself — declaring the bean above is the explicit, one-time opt-in step, the same as every other propagation class in this library.

  • Constructor Details

    • FeignTraceRequestInterceptor

      public FeignTraceRequestInterceptor()
  • Method Details

    • apply

      public void apply(feign.RequestTemplate template)
      Writes the current call chain's trace headers onto template.
      Specified by:
      apply in interface feign.RequestInterceptor
      Parameters:
      template - the outgoing Feign request template