Spring Cloud下通过手动创建Feign客户端进行服务间调用,导致zipkin调用链被截断,traceId不能延续导致调用链断层
解决方案:为Feign.Builder添加请求拦截器,加入请求头X-B3-TraceId和X-B3-SpanId,值为traceIdString和spanIdString
ChannelGatewayPayApi channelGatewayPayApi;
if ((channelGatewayPayApi = channelGatewayApiMap.get(channelInfo.getChnlCode())) == null) {
channelGatewayPayApi = feignConfig.getFeignBuilder()
.requestInterceptor(p -> {
p.header("X-B3-TraceId", TraceHelper.getTraceIdString());
p.header("X-B3-SpanId", TraceHelper.getSpanIdString());
p.header("X-B3-Sampled", String.valueOf(TraceHelper.getSampled()));
log.info("ChannelPayService.cancel TraceId: {}, SpanId: {}", TraceHelper.getTraceIdString(), TraceHelper.getSpanIdString());
}).target(ChannelGatewayPayApi.class, "http://" + channelProduct.getServiceAppName());
channelGatewayApiMap.put(channelInfo.getChnlCode(), channelGatewayPayApi);
channelGatewayMap.put(channelInfo.getChnlCode(), channelProduct.getServiceAppName().substring(channelProduct.getServiceAppName().indexOf("gateway") + 8));
}




