Skip to content

Missing response information from client observation context when filter functions fail #30247

@bclozel

Description

@bclozel

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.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions