package com.sonic.sdk.api.interceptors;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.MDC;

/**
 * Feign请求拦截器
 *
 * @author yinjihuan
 * @create 2017-11-10 17:25
 **/
public class FeignTraceInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        String traceId = MDC.get("TRACE_ID");
        if(StringUtils.isNotEmpty(traceId)){
            requestTemplate.header("X-TRACE-ID", MDC.get("TRACE_ID"));
        }
    }
}
