使用Spring Cloud Sleuth进行的每个HTTP请求之后,清除MDC上下文是否安全?

问题描述 投票:0回答:1

我们在org.springframework.web.filter.OncePerRequestFilter中的每个HTTP请求之后清除MDC上下文。

我们现在要使用Spring Cloud Sleuth。 Spring Cloud Sleuth还设置MDC值。

在每个HTTP请求之后清除整个MDC上下文是否还可以?还是这会干扰Spring Cloud Sleuth?

java spring spring-cloud trace spring-cloud-sleuth
1个回答
1
投票

Spring Cloud Sleuth使用MDC来确保日志条目包含跟踪和跨度ID。如果您在执行日志语句之前清除了这些条目,显然您将不会在日志中获得条目。但是,它不会影响侦探。 Sleuth重用ThreadLocals来存储当前跨度的上下文。

© www.soinside.com 2019 - 2024. All rights reserved.