Avoid recording RestClient observations twice

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
This commit is contained in:
Brian Clozel
2024-06-19 12:46:21 +02:00
parent 098c4b1dd7
commit f7307c9e07
2 changed files with 3 additions and 6 deletions

View File

@@ -73,7 +73,6 @@ class RestClientObservationTests {
@BeforeEach
void setupEach() {
this.client = RestClient.builder()
.messageConverters(converters -> converters.add(0, this.converter))
.requestFactory(this.requestFactory)
@@ -267,6 +266,7 @@ class RestClientObservationTests {
private TestObservationRegistryAssert.TestObservationRegistryAssertReturningObservationContextAssert assertThatHttpObservation() {
TestObservationRegistryAssert.assertThat(this.observationRegistry).hasNumberOfObservationsWithNameEqualTo("http.client.requests",1);
return TestObservationRegistryAssert.assertThat(this.observationRegistry)
.hasObservationWithNameEqualTo("http.client.requests").that();
}