简体   繁体   English

如何将opentrace拦截器添加到restTemplate?

[英]How to add opentrace interceptor to restTemplate?

I want to trace all http requests sent via RestTemplate in my spring(not boot) application.我想在我的 spring(非启动)应用程序中跟踪通过 RestTemplate 发送的所有 http 请求。

I've found class BraveClientHttpRequestInterceptor我找到了 class BraveClientHttpRequestInterceptor

I have concern because this class is deprecated and I don't see any recommended alternative.我很担心,因为这个 class 已被弃用,我没有看到任何推荐的替代方案。 If you know this alternative - please let me know.如果您知道这种替代方法 - 请告诉我。

So I decided to try with deprecated BraveClientHttpRequestInterceptor but I didn't find how instatiate BraveClientHttpRequestInterceptor所以我决定尝试使用已弃用BraveClientHttpRequestInterceptor但我没有发现BraveClientHttpRequestInterceptor如何

I have following configuration:我有以下配置:

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

Appreciate your help.感谢你的帮助。

You might try to set loglevel for org.springframework.web.client.RestTemplate to DEBUG .您可以尝试将org.springframework.web.client.RestTemplate的日志级别设置为DEBUG

You might also find some other possible solutions on https://www.baeldung.com/spring-resttemplate-logging您可能还会在https://www.baeldung.com/spring-resttemplate-logging上找到一些其他可能的解决方案

Please let me know if this is useful.请让我知道这是否有用。

You must inject a RestTemplate using RestTemplateBuilder您必须使用 RestTemplateBuilder 注入 RestTemplate

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

Using this library you should have this configuration that triggers and add the interceptor to the RestBuilder.使用这个库,你应该有这个配置来触发并将拦截器添加到 RestBuilder。 If it doesn't trigger you can do it manually如果它没有触发,您可以手动执行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM