You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3.0.X中http.client.requests指标的URI标签为NONE问题

Spring Boot 3.0.1迁移后RestTemplate URI指标标签显示为none的解决方案需求

将Spring Boot从2.7.5版本迁移至3.0.1版本后,http.client.requests指标的URI标签值在所有场景下均为none。我构建RestTemplate URI的方式如下:

URI uri = UriComponentsBuilder.fromUri(restTemplate.getUriTemplateHandler().expand("/hello"))
   .build()
   .toUri();

return restTemplate.getForObject(uri, String.class);

我习惯使用这种写法,因为添加查询参数时更易读、便于管理。我已分别基于Spring Boot 2.7.7和3.0.1创建示例项目复现该问题,排查后确认此问题与Spring 6的新可观测性特性及Spring Boot Issue #32484相关。

在Spring Boot 2中,框架会自定义UriTemplateHandler,并将urlTemplate存储在ThreadLocal<Deque>中,以此填充URI标签。根据官方文档,我知道两种可行方案:

  • 提供自定义的@Bean ClientRequestObservationConvention来优化标签
  • 使用接收字符串模板的RestTemplate方法,例如:
    return restTemplate.getForObject("/hello", String.class);
    

但我希望找到一种方案,既能保留使用RestTemplate#getForEntity(java.net.URI, java.lang.Class)这类接收URI对象的方法,又能恢复Spring Boot 2中的原有URI标签填充行为。

内容的提问来源于stack exchange,提问作者Matthieu Gabin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 23:50:24