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

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

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

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

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

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

本文链接:https://www.f2er.com/3096116.html

大家都在问