java-jaxrs
java-jaxrs copied to clipboard
Integrate with servlet filter
Jax-rs instrumentation cannot trace all request:
- no URL mapping
- unauthenticated requests
I propose to use servlet filter in conjunction with jax-rs filters. However, jax-rs filters should work alone too, but when there is a span created in filter it should be respected.
@pavolloffay, for the first point, does adding the @PreMatching so that the filter is called before any attempt to match the URL would work ?
@hypnoce I don't know. It probably could work.
If I understand it correctly by default jaxrs filters are executed at post-match request extension point. And priority [2] defines the order for each extension point.
https://docs.oracle.com/javaee/7/api/javax/ws/rs/Priorities.html
[1] https://docs.oracle.com/javaee/7/api/javax/ws/rs/container/ContainerRequestFilter.html
[2] https://docs.oracle.com/javaee/7/api/javax/ws/rs/Priorities.html
[3] preMatch
: https://docs.oracle.com/javaee/7/api/javax/ws/rs/container/PreMatching.html
Recently when I was working on Opentracing in Dropwizard project I noticed that jaxrs and servlet integrations do not play well together, i.e. jaxrs-integration spans are not children of servlet-integration created spans. Maybe original idea was that you should have only one of them installed but not all endpoints have to be handled by jaxrs so it is beneficial to have both.
My idea would be to modify jaxrs integration in such a way that:
- if there is active span (presumably created by servlet integration), don't extract span information from request headers
- if there is no active span - proceed as it is now.
I can work on it in my spare time, but the question is: does it make sense for you?
From my perspective I do not see anything that can go wrong. They should play well together. Nevertheless this issue is still valid in the context of a standalone jaxrs instrumentation.
@tmszdmsk There is one problem. This instrumentation supports @Traced(false)
defined on the jax-rs endpoint. If the span is created in webfilter there is no way how to "cancel" it in the jaxrs layer.
@pavolloffay Shouldn't it be a concern of servlet filter and the developer who is using it? It won't enable servlet filter OOTB, my solution just improves coexistence of two integrations.
But, as @hypnoce said, it is a different issue than originally reported. I will create a separate ticket.