Skip to content

Commit

Permalink
Avoid recording RestClient observations twice
Browse files Browse the repository at this point in the history
Prior to this commit, the fix for gh-32575 introduced cases where the
client observation would be stopped twice.

This commit ensures that `RestClient` observations are stopped only once
when the response is closed, or before throwing an unhanlded exception.

Fixes gh-33068
  • Loading branch information
bclozel committed Jun 19, 2024
1 parent 098c4b1 commit f7307c9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,16 @@ private <T> T readWithMessageConverters(ClientHttpResponse clientResponse, Runna
ResolvableType.forType(bodyType) + "] and content type [" + contentType + "]", cause);
if (observation != null) {
observation.error(restClientException);
observation.stop();
}
throw restClientException;
}
catch (RestClientException restClientException) {
if (observation != null) {
observation.error(restClientException);
}
throw restClientException;
}
finally {
if (observation != null) {
observation.stop();
}
throw restClientException;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class RestClientObservationTests {

@BeforeEach
void setupEach() {

this.client = RestClient.builder()
.messageConverters(converters -> converters.add(0, this.converter))
.requestFactory(this.requestFactory)
Expand Down Expand Up @@ -267,6 +266,7 @@ private void mockResponseBody(String expectedBody, MediaType mediaType) throws E


private TestObservationRegistryAssert.TestObservationRegistryAssertReturningObservationContextAssert assertThatHttpObservation() {
TestObservationRegistryAssert.assertThat(this.observationRegistry).hasNumberOfObservationsWithNameEqualTo("http.client.requests",1);
return TestObservationRegistryAssert.assertThat(this.observationRegistry)
.hasObservationWithNameEqualTo("http.client.requests").that();
}
Expand Down

0 comments on commit f7307c9

Please sign in to comment.