When a WebClient request is build using both : 1. a baseUrl 1. a URI template
then baseUrl
path
seems ignored in the provided metrics tags
Example :
baseUrl
= https://github.com/spring-projects/spring-boot/releases
uriTemplate
= /tag/v{version}
Actual metrics tags :
uri
= /tag/v{version}
client.name
= github.com
I think that metrics tags should not ignore baseUrl
path
(i.e. /spring-projects/spring-boot/releases
)
I've not checked (so I may be wrong), but I don't think there is the same behavior with RestTemplate.
spring-boot version : 2.7.8 / OpenJDK 64-Bit Server VM Temurin-17.0.3+7
Comment From: wilkinsona
The provider uses the URI_TEMPLATE_ATTRIBUTE
which is set by Framework's DefaultRequestBodyUriSpec
. The baseUrl
is configured on the UriBuilderFactory
which the URI spec uses:
attribute(URI_TEMPLATE_ATTRIBUTE, uriTemplate);
return uri(uriBuilderFactory.expand(uriTemplate, uriVariables));
The base URL is applied as part of the expand
call. As you can see, this call is made after the attribute has been set. Things are done in this order as we do not want variables to have been applied to the template before the attribute's set as it would result in an explosion of possible tag values. To fix this, I think the base URL would have to be applied, the attribute set, and then the variable expansion performed.
We'll transfer this issue to the Framework team for further consideration.
Comment From: rstoyanchev
Currently UriTemplateHandler
exposes only methods to expand. If we add a method similar to UriComponents#toUriString
that returns a String with the concatenated components, then this issue would be easy to address along the lines of https://github.com/spring-projects/spring-framework/issues/30027#issuecomment-1443647472.