Skip to content

Commit f6bc828

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-32389
1 parent 0e279fe commit f6bc828

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public Mono<ClientResponse> exchange() {
467467
final AtomicBoolean responseReceived = new AtomicBoolean();
468468
return responseMono
469469
.doOnNext(response -> responseReceived.set(true))
470-
.doOnError(observationContext::setError)
470+
.doOnError(observation::error)
471471
.doFinally(signalType -> {
472472
if (signalType == SignalType.CANCEL && !responseReceived.get()) {
473473
observationContext.setAborted(true);

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

Lines changed: 3 additions & 2 deletions
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

@@ -172,7 +173,7 @@ void recordsObservationWithResponseDetailsWhenFilterFunctionErrors() {
172173
StepVerifier.create(responseMono)
173174
.expectError(IllegalStateException.class)
174175
.verify(Duration.ofSeconds(5));
175-
assertThatHttpObservation()
176+
assertThatHttpObservation().hasError()
176177
.hasLowCardinalityKeyValue("exception", "IllegalStateException")
177178
.hasLowCardinalityKeyValue("status", "200");
178179
}

0 commit comments

Comments
 (0)