排除 Spring Cloud Sleuth 中的资源

Exclude resources in Spring Cloud Sleuth

我正在研究将 Spring Cloud Sleuth 集成到我们正在构建的新 Spring 引导服务中,并希望从生成范围中排除某些 URL,例如运行状况检查端点定期轮询。

检查代码我可以看到在 TraceWebAutoConfiguration.java 中创建的 TraceFilter 有一个 DEFAULT_SKIP_PATTERN,可以通过设置 spring.sleuth.instrument.web.skipPattern 覆盖它。

然而,即使我访问 DEFAULT_SKIP_PATTERN 下的资源,我仍然观察到正在创建跟踪和跨度,即

17:28:46.142 [XNIO-2 task-1] INFO  o.s.c.sleuth.log.Slf4jSpanListener - Starting span: MilliSpan(begin=1454394526140, end=0, name=http/info, traceId=908b24a3-143f-4949-8f86-5df867e3985b, parents=[], spanId=908b24a3-143f-4949-8f86-5df867e3985b, remote=false, exportable=false, annotations={}, processId=null, timelineAnnotations=[])
17:28:46.143 [XNIO-2 task-1] INFO  o.s.c.sleuth.log.Slf4jSpanListener - Continued span: MilliSpan(begin=1454394526140, end=0, name=http/info, traceId=908b24a3-143f-4949-8f86-5df867e3985b, parents=[], spanId=908b24a3-143f-4949-8f86-5df867e3985b, remote=false, exportable=false, annotations={}, processId=null, timelineAnnotations=[])
17:28:46.146 [XNIO-2 task-1] INFO  io.undertow.servlet - Initializing Spring FrameworkServlet 'dispatcherServlet'
17:28:46.146 [XNIO-2 task-1] INFO  o.s.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcherServlet': initialization started
17:28:46.170 [XNIO-2 task-1] INFO  o.s.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcherServlet': initialization completed in 24 ms
17:28:46.216 [XNIO-2 task-1] INFO  o.s.c.sleuth.log.Slf4jSpanListener - Stopped span: MilliSpan(begin=1454394526140, end=1454394526215, name=http/info, traceId=908b24a3-143f-4949-8f86-5df867e3985b, parents=[], spanId=908b24a3-143f-4949-8f86-5df867e3985b, remote=false, exportable=false, annotations={}, processId=null, timelineAnnotations=[])

我错过了什么吗?我目前使用的是 1.0.0.M4

跳过的资源不会阻止跨度的创建,它只会阻止数据的收集和导出。所以你的日志对我来说看起来很正常。在快照中,您会看到 "exportable" 标志在跳过的资源中设置为 false。