{"id":904,"date":"2023-03-11T16:51:04","date_gmt":"2023-03-11T08:51:04","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=904"},"modified":"2023-04-29T15:52:28","modified_gmt":"2023-04-29T07:52:28","slug":"solution-to-zipkin-call-chain-breakage-problem-after-spring-cloud-manually-creating-feign-client","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/11\/solution-to-zipkin-call-chain-breakage-problem-after-spring-cloud-manually-creating-feign-client\/","title":{"rendered":"Spring Cloud\u624b\u52a8\u521b\u5efaFeign\u5ba2\u6237\u7aef\u540ezipkin\u8c03\u7528\u94fe\u65ad\u5c42\u95ee\u9898\u89e3\u51b3"},"content":{"rendered":"<p>Spring Cloud\u4e0b\u901a\u8fc7\u624b\u52a8\u521b\u5efaFeign\u5ba2\u6237\u7aef\u8fdb\u884c\u670d\u52a1\u95f4\u8c03\u7528\uff0c\u5bfc\u81f4zipkin\u8c03\u7528\u94fe\u88ab\u622a\u65ad\uff0ctraceId\u4e0d\u80fd\u5ef6\u7eed\u5bfc\u81f4\u8c03\u7528\u94fe\u65ad\u5c42<\/p>\n<p>\u89e3\u51b3\u65b9\u6848\uff1a\u4e3a<code>Feign.Builder<\/code>\u6dfb\u52a0\u8bf7\u6c42\u62e6\u622a\u5668\uff0c\u52a0\u5165\u8bf7\u6c42\u5934<code>X-B3-TraceId<\/code>\u548c<code>X-B3-SpanId<\/code>\uff0c\u503c\u4e3a<code>traceIdString<\/code>\u548c<code>spanIdString<\/code><\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">ChannelGatewayPayApi channelGatewayPayApi;\nif ((channelGatewayPayApi = channelGatewayApiMap.get(channelInfo.getChnlCode())) == null) {\n    channelGatewayPayApi = feignConfig.getFeignBuilder()\n            .requestInterceptor(p -&gt; {\n                p.header(&quot;X-B3-TraceId&quot;, TraceHelper.getTraceIdString());\n                p.header(&quot;X-B3-SpanId&quot;, TraceHelper.getSpanIdString());\n                p.header(&quot;X-B3-Sampled&quot;, String.valueOf(TraceHelper.getSampled()));\n                log.info(&quot;ChannelPayService.cancel TraceId: {}, SpanId: {}&quot;, TraceHelper.getTraceIdString(), TraceHelper.getSpanIdString());\n            }).target(ChannelGatewayPayApi.class, &quot;http:\/\/&quot; + channelProduct.getServiceAppName());\n    channelGatewayApiMap.put(channelInfo.getChnlCode(), channelGatewayPayApi);\n    channelGatewayMap.put(channelInfo.getChnlCode(), channelProduct.getServiceAppName().substring(channelProduct.getServiceAppName().indexOf(&quot;gateway&quot;) + 8));\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Spring Cloud\u4e0b\u901a\u8fc7\u624b\u52a8\u521b\u5efaFeign\u5ba2\u6237\u7aef\u8fdb\u884c\u670d\u52a1\u95f4\u8c03\u7528\uff0c\u5bfc\u81f4zipkin\u8c03\u7528\u94fe\u88ab\u622a\u65ad\uff0ctrace [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[251,252],"class_list":["post-904","post","type-post","status-publish","format-standard","hentry","category-spring-cloud","tag-feign","tag-zipkin"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=904"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/904\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}