Sleuth 3.0.1 + Spring Cloud Gateway = traceids 与请求/响应无关

问题描述

好吧,我对 Sleuth 3.0.1 进行了新设置,认情况下 spring.sleuth.reactor.instrumentation-type 设置为 manual

因此,我用 WebFluxSleuthOperators.withSpanInScope(tracer,currentTraceContext,exchange,() -> {}) 逻辑包装了所有需要跟踪的地方,它通常将范围放在范围内,但在收到响应之前和之后 traceid 始终不同:

INFO [gateway,2b601780f2242aa9,2b601780f2242aa9] 9 --- [or-http-epoll-1] ...LogFilter    : Request - Username: ...,method: GET,uri: ...
INFO [gateway,] 9 --- [or-http-epoll-1] ...ValidationFilter      : ... Validation passed
INFO [gateway,6a396715ff0979a6,6a396715ff0979a6] 9 --- [or-http-epoll-4] ...LogFilter    : Request - Username: ...,] 9 --- [or-http-epoll-4] ...ValidationFilter      : ... Validation passed
INFO [gateway,020c11ab0c37f8ae,020c11ab0c37f8ae] 9 --- [or-http-epoll-2] ...LogFilter    : Request - Username: ...,] 9 --- [or-http-epoll-2] ...ValidationFilter      : Validation passed
INFO [gateway,189a49553566f771,f51aaaf68e5738d0] 9 --- [or-http-epoll-1] ...LogFilter    : Response - Status: 200 OK
INFO [gateway,92f25dcff9833079,87db5f7b1cbefedb] 9 --- [or-http-epoll-2] ...LogFilter    : Response - Status: 200 OK
INFO [gateway,d8b133f2200e7808,1743df4b5ad37d07] 9 --- [or-http-epoll-1] ...LogFilter    : Response - Status: 400 BAD_REQUEST

深入研究,似乎 exchange.getAttribute(Span.class.getName()); 上返回的跨度在路由后阶段具有不同的跟踪 ID。

当然,将检测类型更改为 decorate_on_last 可以解决问题,但希望避免不必要的性能下降。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)