Sleuth Header X-B3-TraceId 值即使在 Bluemix 中作为 Header 传递给服务请求也会重新生成

Sleuth Header X-B3-TraceId value get Regenerated even if passed to the Service Request as Header In Bluemix

我希望我的服务消费者将 TraceId 作为 Header 参数传递,名称为 X-B3-TraceId 和有效的 128 位十六进制字符串,它们将在后续路径中传播,实际上服务将 return 相同的 Sleuth Trace Id 返回给调用者。我已经使用 Spring Cloud Sleuth 添加了自定义过滤器和跨度提取器以放入服务响应中。

当 App 部署在嵌入式 tomcat 中时,整个设置在我的本地运行良好,但是当相同的 App 部署在 Bluemix 中时,响应没有在请求中传递的相同 Sleuth Trace Id。

在 IBM Bluemix Cloud Foundry 中使用 Sleuth 时,是否存在任何已知的此类缺陷和解决方法?

如果是,能否请您告知如何进行。

我已经在以下位置创建了演示项目:https://github.com/imram/sleuthHeaderIssue

Please Run the Micro Service locally.    
URL: localhost:9090/hello?name=Ram
Header:
    X-B3-TraceId:d61436368bae3c12ce5f844337f3ee52

Service will return:
    HELLORam
    Header:
    Content-Length →8
    Content-Type →text/plain;charset=UTF-8
    Date →Thu, 11 Jan 2018 01:38:48 GMT
    X-Application-Context →application:9090
    X-B3-TraceId →d61436368bae3c12ce5f844337f3ee52

    Note Trace Id is same in RQ and RS.

Deploy Same Service in IBM Bluemix:
    URL: https://sleuth-header-demo.mybluemix.net/hello?name=Ram .
    Header
    X-B3-TraceId:d61436368bae3c12ce5f844337f3ee52

    Response:
       HELLORam
       Header:
       Connection →Keep-Alive
       Content-Type →text/plain;charset=UTF-8
       Date →Thu, 11 Jan 2018 01:38:30 GMT
       Transfer-Encoding →chunked
       X-Application-Context →sleuth-header-demo:bluemix:0
       X-B3-Traceid →b896d05d9f0ae105
       X-Backside-Transport →OK OK
       X-Global-Transaction-ID →2714561407

 See the Trace Id(X-B3-Traceid) got ignore what was present in 
 Request and got Regenerated as b896d05d9f0ae105

你总是需要通过追踪headers。必须传播所有 X-B3 headers 才能使分布式跟踪正常工作。

需要以下2个条件:

  1. header
  2. 中需要 X-B3-TraceId 和 X-B3-SpanId
  3. X-B3 变量的值应该是有效的。
    @GetMapping("/async")
    public String helloSleuthAsync() throws InterruptedException {       
        return "success, traceId:" + MDC.get("X-B3-TraceId");
    }

例如

条件2匹配:

curl --location --request GET 'http://localhost:8080/async' \
--header 'X-B3-TraceId: d61436368bae3c12' \
--header 'X-B3-SpanId: ce5f844337f3ee88'

response: success, traceId:d61436368bae3c12

条件2不匹配:

curl --location --request GET 'http://localhost:8080/async' \
--header 'X-B3-TraceId: marius' \
--header 'X-B3-SpanId: marius'

response:success, traceId:4faae9c09822cf72