com.bizmda.log.trace.FeignTraceInterceptor Maven / Gradle / Ivy
package com.bizmda.log.trace;
import feign.RequestInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
@ConditionalOnClass(value = {RequestInterceptor.class})
public class FeignTraceInterceptor {
// @Resource
// private TraceProperties traceProperties;
@Bean
public RequestInterceptor feignTraceInterceptor() {
return template -> {
//传递日志traceId
String traceId = MDCTraceUtils.getTraceId();
if (!StringUtils.isEmpty(traceId)) {
template.header(MDCTraceUtils.TRACE_ID_HEADER, traceId);
}
};
}
}