首页 > 解决方案 > Sleuth 3.0.1 + Spring Cloud Gateway = traceids 与请求/响应不相关

问题描述

好吧,我有一个使用 Sleuth 3.0.1 的新设置,默认情况下spring.sleuth.reactor.instrumentation-type设置为manual

因此,我用逻辑包裹了我需要跟踪的所有地方,WebFluxSleuthOperators.withSpanInScope(tracer, currentTraceContext, exchange, () -> {})它通常将 span 放在范围内,但在收到响应之前和之后 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: ..., method: GET, uri: ...
INFO [gateway,,] 9 --- [or-http-epoll-4] ...ValidationFilter      : ... Validation passed
INFO [gateway,020c11ab0c37f8ae,020c11ab0c37f8ae] 9 --- [or-http-epoll-2] ...LogFilter    : Request - Username: ..., method: GET, uri: ...
INFO [gateway,,] 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解决问题,但希望避免不必要的性能下降。

标签: spring-webfluxspring-cloud-gatewayspring-cloud-sleuth

解决方案


推荐阅读