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.
When a
WebClientis configured with a customExchangeFilterFunctionlike this: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 theExchangeFunctionof the HTTP connector, plus theExchangeFilterFunctioninstances), the instrumentation will not see the response and will not set it on theClientRequestObservationContext.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.