When a WebClient
is configured with a custom ExchangeFilterFunction
like this:
WebClient.builder().filter(new ExchangeFilterFunction() {
@Override
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
return next.exchange(request).flatMap(response -> {
if (response.headers().header("X-Custom-Header").size() == 0) {
return Mono.error(new IllegalStateException());
}
return Mono.just(response);
});
}
}).build();
The returned error will "short-circuit" the returned publisher and upstream subscriber will not see the HTTP response returned by the remote server. Since the observability instrumentation is done after the global ExchangeFunction
(made of the ExchangeFunction
of the HTTP connector, plus the ExchangeFilterFunction
instances), the instrumentation will not see the response and will not set it on the ClientRequestObservationContext
.
This means that while the recorded observations will contain the error returned by the filter, they will miss information about the actual remote server response.
Comment From: bclozel
Closed with d451d6adccf82