Skip to content
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

JAX-RS unmapped exception metric does not work #490

Open
brainlag opened this issue Feb 21, 2022 · 2 comments
Open

JAX-RS unmapped exception metric does not work #490

brainlag opened this issue Feb 21, 2022 · 2 comments

Comments

@brainlag
Copy link

The assumption that the ContainerResponseFilter is not called if an unmapped exception occurs is simple not true.

@jmartisk
Copy link
Member

jmartisk commented Feb 22, 2022

This depends on the used JAX-RS implementation because the JAX-RS spec does not specify behavior for it. See https://github.com/jakartaee/rest/blob/3.0.0/jaxrs-spec/src/main/asciidoc/chapters/filters_and_interceptors/_exceptions_filters_and_interceptors.adoc :

A response mapped from an exception MUST be processed using the filter chain and the interceptor chain (if an entity is present in the mapped response).

So if there is no entity, the filter does not have to be called.
What implementation and version are we talking about here?
I think we could make it work in both cases by updating the JaxRsMetricsFilter.filter(requestContext, responseContext) method and checking it to see if there was an exception, in which case we wouldn't set the smallrye.metrics.jaxrs.successful property on the request context, but I'm not completely sure we have a reliable way to tell if an exception is mapped or not. I'm not that familar with JAX-RS. Perhaps you have an idea how to do it reliably (and with any JAX-RS implementation, whether the filter is invoked or not), in which case a PR would be welcome.

@brainlag
Copy link
Author

We use Resteasy and from my experience the JAX-RS filters are always called if the resource method is called. Resteasy has 'unhandled' exceptions which would increment this metric, but I couldn't figure out how to trigger it. Maybe some internal Resteasy error. There is no way we can reliably say that exception is unmapped. What we basically want here is if the request returned a 500 status code or not. So just check in the servlet filter the status code and increment this metric if its a 500. Then maybe we need to rename the metric because a mapped exception could return a 500 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants