【问题标题】:How to add opentrace interceptor to restTemplate?如何将opentrace拦截器添加到restTemplate?
【发布时间】:2020-12-17 17:51:37
【问题描述】:

我想在我的 spring(非启动)应用程序中跟踪所有通过 RestTemplate 发送的 http 请求。

我找到了BraveClientHttpRequestInterceptor的班级

我很担心,因为这个类已被弃用,而且我没有看到任何推荐的替代品。如果您知道这种替代方法 - 请告诉我。

所以我决定尝试使用已弃用的BraveClientHttpRequestInterceptor,但我没有发现BraveClientHttpRequestInterceptor 是多么的无效

我有以下配置:

@Bean
public RestTemplate restTemplate(BraveClientHttpRequestInterceptor bci) {
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setInterceptors(bci);
    return restTemplate;
}

感谢您的帮助。

【问题讨论】:

    标签: java spring resttemplate zipkin opentracing


    【解决方案1】:

    您可以尝试将org.springframework.web.client.RestTemplate 的日志级别设置为DEBUG

    您还可以在 https://www.baeldung.com/spring-resttemplate-logging 上找到一些其他可能的解决方案

    如果有用请告诉我。

    【讨论】:

    • 感谢您的回答,但这与我的问题完全无关)跟踪不记录,请阅读opentracing.io/docs/overview
    • 我现在看到了。对不起蜜蜂太快了!祝您解决问题好运!
    【解决方案2】:

    您必须使用 RestTemplateBuilder 注入 RestTemplate

    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder.build();
    }
    

    使用this library 你应该有this configuration 触发并将拦截器添加到RestBuilder。如果它没有触发,您可以手动执行此操作

    【讨论】:

      猜你喜欢
      • 2019-12-22
      • 1970-01-01
      • 1970-01-01
      • 2015-11-08
      • 2021-08-28
      • 2015-11-18
      • 2019-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多