-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Document that WebClient defaultStatusHandler do not apply to exchange* methods #30059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Status handlers can only be declared under That said I'm interested in your comment related to Spring Framework 6 and actuator observations, could you provide more details? It may not be an intended consequence that we should consider and possibly address. |
Sure @rstoyanchev :) Let me give a bit of context on why this is an issue for us: we have a custom framework extending Spring Boot and adding a lot of business-specific defaults like standardized logging format and error handling (among many others). Our framework allows us to opt-out from the default error handler but we still want to put it in place by default, regardless of the client calling Now the observation issue: before the introduction of the Observation API, metrics were calculated by an implementation of the Our problem now is that, by moving the metrics measurement away from the As a temporary solution, we just overwrote the It feels a bit weird given that on |
@rubasace I'm looking at the observation instrumentation aspect of this issue. About this particular section:
If I understand correctly, the application is setting up the client with an
And in this case, the observation is recorded as an error and the HTTP status and other information are missing, since the error signal prevented the actual response from flowing to the instrumentation. I've got a change lined up to fix this, but want to make sure about the following: the observation should still record an error, even if it has been thrown by a filter. In my opinion, it still makes sense to mark the observation as an error because the client code won't be able to consume the response. Do you agree with this behavior? |
Hi @bclozel , actually, the interceptors are throwing the exceptions based on the HTTP status. The reason why is that we cannot add a generic status handler that takes place regardless of the developers using
I understand the thought process but the issue is that this is the behavior that leaves us with no good solution for a global status code handler. It would be ok if somehow the same could be achieved without an exchangeFilter but that's not the case at the moment. PS: this exchangeFilter is not set by the application but by a common company framework aligning 200+ microservices, that's why having a way of configuring this is key for us |
I understand @rubasace , but this point has been answered already by @rstoyanchev in #30059 (comment) - we can't make the default status handler work for I'm repurposing this issue as a documentation to make that clearer in the Javadoc. I've also opened #30247 to fix the observability side of things - this should improve the situation in your case. |
Prior to this commit, an error thrown by a `ExchangeFilterFunction` configured on a `WebClient` instance would be recorded as such by the client observation, but the response details would be missing from the observation. All filter functions and the exchange function (performing the HTTP call) would be merged into a single `ExchangeFunction`; this instance was instrumented and osberved. As a result, the instrumentation would only get the error signal returned by the filter function and would not see the HTTP response even if it was received. This means that the recorded observation would not have the relevant information for the HTTP status. This commit ensures that between the configured `ExchangeFilterFunction` and the `ExchangeFunction`, an instrumentation `ExchangeFilterFunction` is inserted. This allows to set the client response to the observation context, even if a later error signal is thrown by a filter function. Note that with this change, an error signal sent by a filter function will be still recorded in the observation. See gh-30059
That's ok @bclozel , the above-mentioned issue will definitely help. The only thing I'd like to mention is that I understand the point from @rstoyanchev:
But reality is that same idea applies to |
As the title states, the behavior of
WebClient.Builder.defaultStatusHandler()
seems inconsistent. If I'm setting a default status handler my expectation is that it handles the status regardless of how the call is done by the client. This becomes particularly important when customizing the builder from a common library, as I need to enforce that the default handling always takes place; Prior to Spring Framework 6 and Spring Boot 3, this could be done via anExchangeFilterFunction
. Now, things get more complicated as exceptions thrown from the exchange filter functions affect the actuator observations, forcing me to override quite some methods just to be able to not lose the response HTTP status on them.As for documentation, I couldn't find anywhere where this is documented either and, on StackOverflow answers, everything seems to indicate that
retrieve()
is just a simplification of theexchangeTo*
methods when we don't care about more granular control.Taking all the above into consideration, I'm wondering if there's a good reason why
defaultStatusHandler()
does only apply toretrieve()
calls. Even if that were the case, I think this should be somehow stated in the documentation.The text was updated successfully, but these errors were encountered: