Commit 809a3965 authored by Brian Clozel's avatar Brian Clozel

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
parent 82949b9c
...@@ -37,13 +37,9 @@ public class DefaultWebClientExchangeTagsProvider implements WebClientExchangeTa ...@@ -37,13 +37,9 @@ public class DefaultWebClientExchangeTagsProvider implements WebClientExchangeTa
Tag method = WebClientExchangeTags.method(request); Tag method = WebClientExchangeTags.method(request);
Tag uri = WebClientExchangeTags.uri(request); Tag uri = WebClientExchangeTags.uri(request);
Tag clientName = WebClientExchangeTags.clientName(request); Tag clientName = WebClientExchangeTags.clientName(request);
if (response != null) { return Arrays.asList(method, uri, clientName,
return Arrays.asList(method, uri, clientName, WebClientExchangeTags.status(response), (response != null) ? WebClientExchangeTags.status(response) : WebClientExchangeTags.status(throwable),
WebClientExchangeTags.outcome(response)); WebClientExchangeTags.outcome(response));
}
else {
return Arrays.asList(method, uri, clientName, WebClientExchangeTags.status(throwable));
}
} }
} }
...@@ -77,14 +77,14 @@ class DefaultWebClientExchangeTagsProviderTests { ...@@ -77,14 +77,14 @@ class DefaultWebClientExchangeTagsProviderTests {
void tagsWhenIoExceptionShouldReturnIoErrorStatus() { void tagsWhenIoExceptionShouldReturnIoErrorStatus() {
Iterable<Tag> tags = this.tagsProvider.tags(this.request, null, new IOException()); Iterable<Tag> tags = this.tagsProvider.tags(this.request, null, new IOException());
assertThat(tags).containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/projects/{project}"), assertThat(tags).containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/projects/{project}"),
Tag.of("clientName", "example.org"), Tag.of("status", "IO_ERROR")); Tag.of("clientName", "example.org"), Tag.of("status", "IO_ERROR"), Tag.of("outcome", "UNKNOWN"));
} }
@Test @Test
void tagsWhenExceptionShouldReturnClientErrorStatus() { void tagsWhenExceptionShouldReturnClientErrorStatus() {
Iterable<Tag> tags = this.tagsProvider.tags(this.request, null, new IllegalArgumentException()); Iterable<Tag> tags = this.tagsProvider.tags(this.request, null, new IllegalArgumentException());
assertThat(tags).containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/projects/{project}"), assertThat(tags).containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/projects/{project}"),
Tag.of("clientName", "example.org"), Tag.of("status", "CLIENT_ERROR")); Tag.of("clientName", "example.org"), Tag.of("status", "CLIENT_ERROR"), Tag.of("outcome", "UNKNOWN"));
} }
} }
...@@ -1981,10 +1981,11 @@ following information: ...@@ -1981,10 +1981,11 @@ following information:
|`outcome` |`outcome`
|Request's outcome based on the status code of the response. 1xx is |Request's outcome based on the status code of the response. 1xx is
`INFORMATIONAL`, 2xx is `SUCCESS`, 3xx is `REDIRECTION`, 4xx `CLIENT_ERROR`, and 5xx is `INFORMATIONAL`, 2xx is `SUCCESS`, 3xx is `REDIRECTION`, 4xx `CLIENT_ERROR`, and 5xx is
`SERVER_ERROR` `SERVER_ERROR`, `UNKNOWN` otherwise
|`status` |`status`
|Response's HTTP status code (for example, `200` or `500`) |Response's HTTP status code if available (for example, `200` or `500`),
or `IO_ERROR` in case or I/O issues, `CLIENT_ERROR` otherwise
|`uri` |`uri`
|Request's URI template prior to variable substitution, if possible (for example, |Request's URI template prior to variable substitution, if possible (for example,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment