Spring Cloud手动创建Feign客户端后zipkin调用链断层问题解决

Spring Cloud下通过手动创建Feign客户端进行服务间调用,导致zipkin调用链被截断,traceId不能延续导致调用链断层

解决方案:为Feign.Builder添加请求拦截器,加入请求头X-B3-TraceIdX-B3-SpanId,值为traceIdStringspanIdString

1
2
3
4
5
6
7
8
9
10
11
12
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));
}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :