-
Notifications
You must be signed in to change notification settings - Fork 15
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
✨ Add support for filtering requests to APIS defined with JAX-RS #320
Comments
@pavolloffay I'm taking a look at the dropwizard Jersey/Jetty use case! I hear you were looking at this a while back, so if you've got any opinions on where I should start out let me know! |
What exactly do you mean by fitlering? Do you mean disabling tracing for predefined endpoints/URL patterns? |
Sorry, I should have been more clear! I mean supporting the reporting of the request body/headers and blocking a request using an implementation of I did some exploratory testing of this and found some surprising results. Using a Dropwizard sample application, we report the request/response bodies, headers, and can block requests using a However, it is not necessary to run Jersey JAX-RS application on Jetty with a Java EE Servlet filter. If you build a simple Jersey JAX-RS application running on Jetty but without using Dropwizard, we won't report the request/response bodies and headers and the |
Usually, JAX-RS runs on top of the servlet implementation (or netty for reactive ones).
This is surprising, I guess it also depends on how the application is bootstrapped because Jersey for sure offers servlet integration. If what you are describing is true then Jersey implements directly Jetty hander/API. There might be different solutions to this:
in both of these scenarios you have to be sure that instrumentations on multiple levels do not interfere (e.g. either servlet or JAX-RS instrumentation runs). I would go with the second option for now as it provides better coverage. Note that OTEL agent instruments servlet containers/APP server (e.g. to create events for unmatched requests) and in the past there was a bug with Undertow - the undertow instrumentation finished early span causing our instrumentation to be noop. A finished span is not recording events and in this case our instrumentation is noop. Before proceeding with implementing additional instrumentation I would run |
Yes! There are two ways, as I understand it, to run Jersey on Jetty I was referring to the I'm leaning towards instrumenting the HTTP servers/containers because I think we should be able to leverage some existing instrumentation from OTEL and the alternative would probably mean writing instrumentation for each JAX-RS implementation we come across. |
This is not how JAX-RS works. You should be able to write single JAX-RS instrumentation and use it for all implementations. The span lifecycle (creation, finish, error capture) is already handled by OTEL server instrumentations (e.g. jetty in this case). As I mentioned before the direct server instrumentation might have only a single advantage - capturing unmapped requests (e.g. requests that target URL outside of the application context path). However, there is pre-matching discriminator in JAX-RS that might solve this https://www.logicbig.com/tutorials/java-ee-tutorial/jax-rs/filters-pre-matching.html. Also, have a look at Smallrye JWT how handles blocking in JAX-RS filter: https://github.com/smallrye/smallrye-jwt/blob/main/implementation/jwt-jaxrs/src/main/java/io/smallrye/jwt/auth/jaxrs/JWTAuthenticationFilter.java#L82 |
Use Case
We should support filtering requests made to APIs defined with the JAX-RS API, just as we do for the Java EE Servlet API.
Proposal
I think it will likely make sense to leverage similar strategies for instrumenting JAX-RS resources as is done by OpenTelemetry (in these modules). We'll likely be able to do the bulk of the work according to the JAX-RS API with minor tweaks here and there for each JAX-RS implementation we want to support.
Questions to address (if any)
The specific use case I'm trying to help solve is a Jersey JAX-RS web application running on Jetty leveraging Dropwizard. It's possible it could make sense to add support for this use case by targeting Jetty internals like we do for Netty, which is another solution worth considering
The text was updated successfully, but these errors were encountered: