spring-cloud-gateway - Spring cloud gateway和spring sleuth集成在延迟异步调用后不起作用
问题描述
在将 spring-cloud-gateway 和 spring sleuth 升级到 3.0.2 之后,对我在我的产品中使用的一个用例进行了一些测试。在过滤器链中发出异步请求后,后续过滤器不会获得 traceId 和 spanId。
请求 -> TestFilter(异步延迟调用)(存在 Traceid 和 spanid)-> LoggingFilter(没有跟踪 id 和 span id)。
日志输出示例
2021-04-05 15:24:44.204 INFO [testapp,,] 2952 --- [ main] c.c.s.SpringsleuthexampleApplication : Started SpringsleuthexampleApplication in 17.733 seconds (JVM running for 18.419)
2021-04-05 15:24:50.329 INFO [**testapp,606ade6a3d59693bc6bbdccde0438597,c6bbdccde0438597**] 2952 --- [ttp@67e28be3-21] c.c.s.filter.TestFilter : Test Filter Incoming-1
2021-04-05 15:24:55.334 INFO [**testapp,,**] 2952 --- [ parallel-1] c.c.s.filter.TestFilter : Test Filter Incoming-2
2021-04-05 15:24:55.335 INFO [**testapp,,**] 2952 --- [ parallel-1] c.c.s.filter.LoggingFilter : Incoming request
2021-04-05 15:25:11.657 INFO [**testapp,,**] 2952 --- [ctor-http-nio-2] c.c.s.filter.LoggingFilter : Outgoing response
示例项目 spring-cloud-sleuth-integration.zip
卷曲以测试 API。
curl --location --request GET 'http://localhost:8080/test/get'
--header 'Content-Type: application/json'
如果我们从代码(TestFilter.java)中删除异步调用的延迟,如下所示。
public Mono<String> testAsync() {
return Mono.just("test");// .delayElement(Duration.ofSeconds(5));
}
然后有效地记录 print traceid 和 spanid ,如下所示。
2021-04-05 15:33:24.168 INFO [**testapp,606ae06cadef33fdcd761e928c4ae866,cd761e928c4ae866**] 16396 --- [http@e344ad3-37] c.c.s.filter.TestFilter : Test Filter Incoming-1
2021-04-05 15:33:24.169 INFO [**testapp,606ae06cadef33fdcd761e928c4ae866,cd761e928c4ae866**] 16396 --- [http@e344ad3-37] c.c.s.filter.TestFilter : Test Filter Incoming-2
2021-04-05 15:33:24.170 INFO [**testapp,606ae06cadef33fdcd761e928c4ae866,cd761e928c4ae866**] 16396 --- [http@e344ad3-37] c.c.s.filter.LoggingFilter : Incoming request
2021-04-05 15:33:39.755 INFO [testapp,,] 16396 --- [ctor-http-nio-2] c.c.s.filter.LoggingFilter : Outgoing response
解决方案
推荐阅读
- r - 如何结合两个调查并使用 svydesign 设置适当的参数
- file-handling - 想要摆脱文件处理中的覆盖
- python - 类型错误:无法腌制 _thread.RLock 对象
- android - 为什么要布局
标签不能与 BottomSheetBehavior 一起正常工作? - vpn - 如何在家中打开公司服务器内的 Web 应用程序?
- nginx - NGINX Amazon EC2 允许通过 80 端口继续加载
- html - 如何使用css将椭圆或圆与线连接
- java - 正则表达式查找以任何语言调用的所有方法
- networking - 到本地主机的 GCloud SSH 隧道
- android - 在受信任的 Web 活动中,地址栏没有隐藏