Align WebClient uri metric tag with RestTemplate
Prior to this commit, the `WebClientExchangeTags`, when given a request without a string template, would only get the request path to create the "uri" tag for metrics. This is inconsistent with the `RestTemplateExchangeTags`, which are taking the full request URI minus the protocol+host+port. This commit aligns the `WebClientExchangeTags` behavior in this case. Closes gh-22832
This commit is contained in:
parent
9c408babfa
commit
d2e67ab84d
|
@ -66,7 +66,7 @@ public final class WebClientExchangeTags {
|
|||
* @return the uri tag
|
||||
*/
|
||||
public static Tag uri(ClientRequest request) {
|
||||
String uri = (String) request.attribute(URI_TEMPLATE_ATTRIBUTE).orElseGet(() -> request.url().getPath());
|
||||
String uri = (String) request.attribute(URI_TEMPLATE_ATTRIBUTE).orElseGet(() -> request.url().toString());
|
||||
return Tag.of("uri", extractPath(uri));
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,14 @@ class WebClientExchangeTagsTests {
|
|||
assertThat(WebClientExchangeTags.uri(this.request)).isEqualTo(Tag.of("uri", "/projects/spring-boot"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void uriWhenTemplateIsMissingShouldReturnPathWithQueryParams() {
|
||||
this.request = ClientRequest
|
||||
.create(HttpMethod.GET, URI.create("https://example.org/projects/spring-boot?section=docs")).build();
|
||||
assertThat(WebClientExchangeTags.uri(this.request))
|
||||
.isEqualTo(Tag.of("uri", "/projects/spring-boot?section=docs"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void clientName() {
|
||||
assertThat(WebClientExchangeTags.clientName(this.request)).isEqualTo(Tag.of("clientName", "example.org"));
|
||||
|
|
Loading…
Reference in New Issue