herman shafiq
herman shafiq

Reputation: 501

MDC Context Propagation in FeignClient

I have been trying to propogate the MDC details will calling an API using FeignClient. In an async way. Here is my FeignClient Details. Im not sure what am i missing.

@Configuration
public class FeignClientConfig {

  @Bean
  RequestContextListener requestContextListener() {
    return new RequestContextListener();
  }

  @Bean
  RequestInterceptor requestInterceptor() {
    return requestTemplate -> {

      log.info("traceparent....{}", MDC.getCopyOfContextMap());

      requestTemplate.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
      requestTemplate.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
      requestTemplate.header(CustomHttpHeaders.SERVICE_NAME, applicationName);
    };
  }

  @Bean
  Request.Options requestOptions() {
    return new Request.Options(connectTimeout, TimeUnit.MILLISECONDS, readTimeout,
        TimeUnit.MILLISECONDS, true);
  }
}

Logs are here.

2024-11-11 02:03:11.254 INFO  [accounts,SME,8e56bc83efca861ba6cb89f517025cab,6e18a3acf3bdfae6,23a837b4-b0a1-47fb-bad4-cf953a9df791,asyncExecutor-4] c.a.i.c.s.integration.IntegrationService | Here Im Service
2024-11-11 02:03:11.279 INFO  [accounts,,,,,pool-3-thread-2] c.a.ib.commons.configuration.FeignClientConfig | traceparent....null

Upvotes: 0

Views: 50

Answers (0)

Related Questions