Skip to content

Commit

Permalink
Set error on observation in WebClient instrumentation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bclozel committed Mar 8, 2024
1 parent 0e279fe commit f6bc828
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Expand Up @@ -467,7 +467,7 @@ public Mono<ClientResponse> exchange() {
final AtomicBoolean responseReceived = new AtomicBoolean();
return responseMono
.doOnNext(response -> responseReceived.set(true))
.doOnError(observationContext::setError)
.doOnError(observation::error)
.doFinally(signalType -> {
if (signalType == SignalType.CANCEL && !responseReceived.get()) {
observationContext.setAborted(true);
Expand Down
Expand Up @@ -110,7 +110,8 @@ void recordsObservationForErrorExchange() {
StepVerifier.create(client.get().uri("/path").retrieve().bodyToMono(Void.class))
.expectError(IllegalStateException.class)
.verify(Duration.ofSeconds(5));
assertThatHttpObservation().hasLowCardinalityKeyValue("exception", "IllegalStateException")
assertThatHttpObservation().hasError()
.hasLowCardinalityKeyValue("exception", "IllegalStateException")
.hasLowCardinalityKeyValue("status", "CLIENT_ERROR");
}

Expand Down Expand Up @@ -172,7 +173,7 @@ void recordsObservationWithResponseDetailsWhenFilterFunctionErrors() {
StepVerifier.create(responseMono)
.expectError(IllegalStateException.class)
.verify(Duration.ofSeconds(5));
assertThatHttpObservation()
assertThatHttpObservation().hasError()
.hasLowCardinalityKeyValue("exception", "IllegalStateException")
.hasLowCardinalityKeyValue("status", "200");
}
Expand Down

0 comments on commit f6bc828

Please sign in to comment.