spring-cloud-sleuth - 如何使用 Spring Cloud Sleuth 和 Spring Cloud Gateway 删除 WARN 消息

我需要在 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 消息(https://github.com/taxone/sleuth-gateway-actuator/tree/main#readme):

[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

经过调查,我发现了https://github.com/spring-cloud/spring-cloud-sleuth/pull/1680。似乎这不会导致真正的问题,但我想知道是否可以创建一个配置来防止在启动时引发异常。

示例项目https://github.com/taxone/sleuth-gateway-actuator

回答1

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

更新:

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

相似文章

最新文章