如何使用 Spring Cloud Sleuth 和 Spring Cloud Gateway 删除 WARN 消息

How to remove WARN message using Spring Cloud Sleuth and Spring Cloud Gateway

我需要在 Netty 日志中记录痕迹,所以我添加了这个配置:

@Configuration
public class SleuthGWConfiguration {

    @Bean
    public HttpClientCustomizer customizer(HttpTracing httpTracing) {
        return (c) -> {
            return ReactorNettyHttpTracing.create(httpTracing).decorateHttpClient(c);


        };
    }
}

并且日志包含预期的痕迹:

[2m2022-05-18 18:16:16.306[0;39m [32mDEBUG [,,][0;39m [35m19820[0;39m [2m---[0;39m [2m[ctor-http-nio-2][0;39m [36mreactor.netty.http.server.HttpServer    [0;39m [2m:[0;39m [08685324-1, L:/0:0:0:0:0:0:0:1:8080 - R:/0:0:0:0:0:0:0:1:59765] Handler is being applied: org.springframework.http.server.reactive.ReactorHttpHandlerAdapter@130d2eee
[2m2022-05-18 18:16:16.910[0;39m [32mDEBUG [,efbd8bcbe33f76e3,efbd8bcbe33f76e3][0;39m [35m19820[0;39m [2m---[0;39m [2m[ctor-http-nio-2][0;39m [36mr.netty.http.client.HttpClientConnect   [0;39m [2m:[0;39m [1a19d87a-1, L:/127.0.0.1:59767 - R:localhost/127.0.0.1:8085] Handler is being applied: {uri=http://localhost:8085/get, method=GET}
[2m2022-05-18 18:16:16.936[0;39m [32mDEBUG [,efbd8bcbe33f76e3,761f2b4fd9a180ba][0;39m [35m19820[0;39m [2m---[0;39m [2m[ctor-http-nio-2][0;39m [36mr.n.http.client.HttpClientOperations    [0;39m [2m:[0;39m [1a19d87a-1, L:/127.0.0.1:59767 - R:localhost/127.0.0.1:8085] Received response (auto-read:false) : [Server=gunicorn/19.9.0, Date=Wed, 18 May 2022 16:16:16 GMT, Connection=keep-alive, Content-Type=application/json, Access-Control-Allow-Origin=*, Access-Control-Allow-Credentials=true, content-length=1382]
[2m2022-05-18 18:16:16.944[0;39m [32mDEBUG [,efbd8bcbe33f76e3,efbd8bcbe33f76e3][0;39m [35m19820[0;39m [2m---[0;39m [2m[ctor-http-nio-2][0;39m [36mr.n.http.client.HttpClientOperations    [0;39m [2m:[0;39m [1a19d87a-1, L:/127.0.0.1:59767 - R:localhost/127.0.0.1:8085] Received last HTTP packet
[2m2022-05-18 18:16:16.966[0;39m [32mDEBUG [,efbd8bcbe33f76e3,efbd8bcbe33f76e3][0;39m [35m19820[0;39m [2m---[0;39m [2m[ctor-http-nio-2][0;39m [36mr.n.http.server.HttpServerOperations    [0;39m [2m:[0;39m [08685324-1, L:/0:0:0:0:0:0:0:1:8080 - R:/0:0:0:0:0:0:0:1:59765] Last HTTP response frame

但是在应用程序启动时出现带有 大堆栈 跟踪的 WARN 消息 (complete stack trace is here):

[36mo.s.c.s.a.i.w.SkipPatternConfiguration  [0;39m [2m:[0;39m Most likely, there is an actuator endpoint that indirectly references an instrumented HTTP client. An exception was thrown during bean initialization. Will ignore that exception

调查后发现the related issue。看起来这不会导致真正的问题,但我想知道是否可以创建一个配置来防止在启动时抛出异常。

示例项目是available here

只需设置一个属性logging.level.org.springframework.cloud.sleuth.autoconfig.instrument.web.SkipPatternConfiguration=ERROR。你可以做到,例如通过 application.yml

更新:

对于这个问题https://github.com/spring-cloud/spring-cloud-sleuth/issues/2166,我们正在通过降低日志记录的严重性来降低噪音