package com.java110.core.trace;

import com.java110.core.log.LoggerFactory;
import com.java110.dto.trace.TraceAnnotationsDto;
import com.java110.dto.trace.TraceDto;
import com.java110.utils.constant.CommonConstant;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import org.slf4j.Logger;

import java.io.IOException;

//@Component
public class Java110FeignClientInterceptor implements Interceptor {
    private static Logger logger = LoggerFactory.getLogger(Java110FeignClientInterceptor.class);

    @Override
    public Response intercept(Chain chain) throws IOException {
        // Request request = chain.request();

        Request.Builder builder = chain.request().newBuilder();
        //调用链头信息
        TraceDto traceDto = Java110TraceFactory.getTraceDto();
        if (traceDto != null) {
            builder.header(CommonConstant.TRACE_ID, traceDto.getTraceId());
            builder.header(CommonConstant.PARENT_SPAN_ID, traceDto.getId());
        }
        logger.debug("feign 进入 Java110FeignClientAop>> intercept");
        Java110TraceFactory.putAnnotations(TraceAnnotationsDto.VALUE_SERVER_SEND);
        try {
            Response response = chain.proceed(builder.build());
            //after
            return response;
        } catch (Exception e) {
            //log error
            throw e;
        } finally {
            //clean up
            Java110TraceFactory.putAnnotations(TraceAnnotationsDto.VALUE_SERVER_RECEIVE);
        }
    }


}

@@ -30,51 +30,8 @@
 e;%0A%0A
-import com.java110.core.log.LoggerFactory;%0A
 impo
@@ -245,33 +245,8 @@
 nse;
-%0Aimport org.slf4j.Logger;
 %0A%0Aim
@@ -356,16 +356,19 @@
 or %7B%0A   
+ //
  private
@@ -926,16 +926,18 @@
         
+//
 logger.d

优化 工作办理