首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Spring cloud Sleuth - traceId不传播RestTemplate

Spring cloud Sleuth - traceId不传播RestTemplate
EN

Stack Overflow用户
提问于 2021-07-19 17:02:56
回答 1查看 249关注 0票数 0

我正在尝试使用Spring cloud Sleuth,但是我面临着拥有适当的日志信息的问题。我的应用程序不传播RestTemplate的traceId和spanId。

我使用的是最新版本的Sleuth。

代码语言:javascript
运行
复制
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-sleuth</artifactId>
  <version>3.0.3</version>
</dependency>

以下是日志:

代码语言:javascript
运行
复制
2021-07-19 10:46:22.834 DEBUG [My app,340b0c68ce92b6be,340b0c68ce92b6be] 28840 --- [       Thread-3] org.apache.http.headers                  : http-outgoing-0 << Date: Mon, 19 Jul 2021 08:46:15 GMT
2021-07-19 10:46:22.834 DEBUG [My app,340b0c68ce92b6be,340b0c68ce92b6be] 28840 --- [       Thread-3] o.a.http.impl.execchain.MainClientExec   : Connection can be kept alive indefinitely
2021-07-19 10:46:22.834 DEBUG [My app,,] 28840 --- [       Thread-3] o.s.web.client.RestTemplate              : Response 200 OK
2021-07-19 10:46:22.834 DEBUG [My app,,] 28840 --- [       Thread-3] o.s.web.client.RestTemplate              : Reading to [com.app.myapp.DeviceService]
2021-07-19 10:46:22.834 DEBUG [My app,,] 28840 --- [       Thread-3] h.i.c.PoolingHttpClientConnectionManager : Connection [id: 0][route: {s}->https://ttsce.dot.eu:443] can be kept alive indefinitely
2021-07-19 10:46:22.844 DEBUG [My app,,] 28840 --- [       Thread-3] .w.m.TracingClientHttpRequestInterceptor : Wrapping an outbound http call with span [NoopSpan(4bda0829902d27f6/4bda0829902d27f6)]
2021-07-19 10:46:22.844 DEBUG [My app,4bda0829902d27f6,4bda0829902d27f6] 28840 --- [       Thread-3] o.a.h.client.protocol.RequestAddCookies  : CookieSpec selected: default

这就是我如何创建我的RestTemplate bean (我正在使用bean的这两个设置进行测试)。

代码语言:javascript
运行
复制
@Primary
@Bean("newRestTemplate")
public RestTemplate restTemplate() {
    return new RestTemplate();
}

@Bean("customRestTemplate")
public RestTemplate restTemplate(RestTemplateBuilder builder) {
    return builder.setConnectTimeout(Duration.ofMillis(300000))
            .setReadTimeout(Duration.ofMillis(300000)).build();
}
EN

回答 1

Stack Overflow用户

发布于 2021-07-19 22:14:12

你能提供你正在使用的Sleuth和Cloud的哪个版本吗?RestTemplate是测试最多的组件,它确实可以工作。这里有一个使用rest模板的独立应用程序示例,它可以使用https://github.com/spring-cloud-samples/spring-cloud-sleuth-samples/tree/main/resttemplate

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68437814

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档