Skip to content

Commit d2e67ab

Browse files
committed
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
1 parent 9c408ba commit d2e67ab

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static Tag method(ClientRequest request) {
6666
* @return the uri tag
6767
*/
6868
public static Tag uri(ClientRequest request) {
69-
String uri = (String) request.attribute(URI_TEMPLATE_ATTRIBUTE).orElseGet(() -> request.url().getPath());
69+
String uri = (String) request.attribute(URI_TEMPLATE_ATTRIBUTE).orElseGet(() -> request.url().toString());
7070
return Tag.of("uri", extractPath(uri));
7171
}
7272

Diff for: spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ void uriWhenTemplateIsMissingShouldReturnPath() {
7878
assertThat(WebClientExchangeTags.uri(this.request)).isEqualTo(Tag.of("uri", "/projects/spring-boot"));
7979
}
8080

81+
@Test
82+
void uriWhenTemplateIsMissingShouldReturnPathWithQueryParams() {
83+
this.request = ClientRequest
84+
.create(HttpMethod.GET, URI.create("https://example.org/projects/spring-boot?section=docs")).build();
85+
assertThat(WebClientExchangeTags.uri(this.request))
86+
.isEqualTo(Tag.of("uri", "/projects/spring-boot?section=docs"));
87+
}
88+
8189
@Test
8290
void clientName() {
8391
assertThat(WebClientExchangeTags.clientName(this.request)).isEqualTo(Tag.of("clientName", "example.org"));

0 commit comments

Comments
 (0)