Spring Cloud手动创建Feign客户端后zipkin调用链断层问题解决
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));
}
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/11/solution-to-zipkin-call-chain-breakage-problem-after-spring-cloud-manually-creating-feign-client/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
打赏
海报
Spring Cloud手动创建Feign客户端后zipkin调用链断层问题解决
Spring Cloud下通过手动创建Feign客户端进行服务间调用,导致zipkin调用链被截断,traceId不能延续导致调用链断层
解决方案:为Feign.Builder添加请求拦截器,……
文章目录
关闭
共有 0 条评论