Skip to content

Commit 809a396

Browse files
committed
Add missing outcome tag for WebClient metrics
On error cases, the "outcome" tag would be missing from recorded metrics for the `WebClient`. This commit fixes this issue and improves the reference documentation by mentioning the tag values used for error cases, when the client response is not received (I/O errors, client error, etc). Fixes gh-17219
1 parent 82949b9 commit 809a396

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProvider.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,9 @@ public Iterable<Tag> tags(ClientRequest request, ClientResponse response, Throwa
3737
Tag method = WebClientExchangeTags.method(request);
3838
Tag uri = WebClientExchangeTags.uri(request);
3939
Tag clientName = WebClientExchangeTags.clientName(request);
40-
if (response != null) {
41-
return Arrays.asList(method, uri, clientName, WebClientExchangeTags.status(response),
42-
WebClientExchangeTags.outcome(response));
43-
}
44-
else {
45-
return Arrays.asList(method, uri, clientName, WebClientExchangeTags.status(throwable));
46-
}
40+
return Arrays.asList(method, uri, clientName,
41+
(response != null) ? WebClientExchangeTags.status(response) : WebClientExchangeTags.status(throwable),
42+
WebClientExchangeTags.outcome(response));
4743
}
4844

4945
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/DefaultWebClientExchangeTagsProviderTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ void tagsWhenNoUriTemplateShouldProvideUriPath() {
7777
void tagsWhenIoExceptionShouldReturnIoErrorStatus() {
7878
Iterable<Tag> tags = this.tagsProvider.tags(this.request, null, new IOException());
7979
assertThat(tags).containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/projects/{project}"),
80-
Tag.of("clientName", "example.org"), Tag.of("status", "IO_ERROR"));
80+
Tag.of("clientName", "example.org"), Tag.of("status", "IO_ERROR"), Tag.of("outcome", "UNKNOWN"));
8181
}
8282

8383
@Test
8484
void tagsWhenExceptionShouldReturnClientErrorStatus() {
8585
Iterable<Tag> tags = this.tagsProvider.tags(this.request, null, new IllegalArgumentException());
8686
assertThat(tags).containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/projects/{project}"),
87-
Tag.of("clientName", "example.org"), Tag.of("status", "CLIENT_ERROR"));
87+
Tag.of("clientName", "example.org"), Tag.of("status", "CLIENT_ERROR"), Tag.of("outcome", "UNKNOWN"));
8888
}
8989

9090
}

spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,10 +1981,11 @@ following information:
19811981
|`outcome`
19821982
|Request's outcome based on the status code of the response. 1xx is
19831983
`INFORMATIONAL`, 2xx is `SUCCESS`, 3xx is `REDIRECTION`, 4xx `CLIENT_ERROR`, and 5xx is
1984-
`SERVER_ERROR`
1984+
`SERVER_ERROR`, `UNKNOWN` otherwise
19851985

19861986
|`status`
1987-
|Response's HTTP status code (for example, `200` or `500`)
1987+
|Response's HTTP status code if available (for example, `200` or `500`),
1988+
or `IO_ERROR` in case or I/O issues, `CLIENT_ERROR` otherwise
19881989

19891990
|`uri`
19901991
|Request's URI template prior to variable substitution, if possible (for example,

0 commit comments

Comments
 (0)