java-jaxrs icon indicating copy to clipboard operation
java-jaxrs copied to clipboard

Integrate with servlet filter

Open pavolloffay opened this issue 8 years ago • 7 comments

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 avatar Feb 20 '17 15:02 pavolloffay

@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 avatar Oct 29 '17 17:10 hypnoce

@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

pavolloffay avatar Oct 30 '17 08:10 pavolloffay

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?

tmszdmsk avatar Jan 30 '18 22:01 tmszdmsk

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.

hypnoce avatar Jan 31 '18 00:01 hypnoce

@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 avatar Jan 31 '18 08:01 pavolloffay

@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.

tmszdmsk avatar Jan 31 '18 08:01 tmszdmsk

But, as @hypnoce said, it is a different issue than originally reported. I will create a separate ticket.

tmszdmsk avatar Jan 31 '18 08:01 tmszdmsk