Skip to content

Commit ec2c9b5

Browse files
committed
Set error on observation in WebClient instrumentation
Prior to this commit, error signals flowing from the client response publisher in `WebClient` would be set on the `Observation.Context`. This is enough for the observation convention to collect data about the error but observation handlers are not notified of this error. This commit sets the error instead on the observation directly to fix this issue. Fixes gh-32399
1 parent 36539bd commit ec2c9b5

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ public Mono<ClientResponse> exchange() {
465465
final AtomicBoolean responseReceived = new AtomicBoolean();
466466
return responseMono
467467
.doOnNext(response -> responseReceived.set(true))
468-
.doOnError(observationContext::setError)
468+
.doOnError(observation::error)
469469
.doFinally(signalType -> {
470470
if (signalType == SignalType.CANCEL && !responseReceived.get()) {
471471
observationContext.setAborted(true);

spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientObservationTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ void recordsObservationForErrorExchange() {
110110
StepVerifier.create(client.get().uri("/path").retrieve().bodyToMono(Void.class))
111111
.expectError(IllegalStateException.class)
112112
.verify(Duration.ofSeconds(5));
113-
assertThatHttpObservation().hasLowCardinalityKeyValue("exception", "IllegalStateException")
113+
assertThatHttpObservation().hasError()
114+
.hasLowCardinalityKeyValue("exception", "IllegalStateException")
114115
.hasLowCardinalityKeyValue("status", "CLIENT_ERROR");
115116
}
116117

@@ -180,7 +181,7 @@ void recordsObservationWithResponseDetailsWhenFilterFunctionErrors() {
180181
StepVerifier.create(responseMono)
181182
.expectError(IllegalStateException.class)
182183
.verify(Duration.ofSeconds(5));
183-
assertThatHttpObservation()
184+
assertThatHttpObservation().hasError()
184185
.hasLowCardinalityKeyValue("exception", "IllegalStateException")
185186
.hasLowCardinalityKeyValue("status", "200");
186187
}

0 commit comments

Comments
 (0)