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 ContainerRequestContextFilter instrumentation #1134

Merged
merged 6 commits into from
Dec 11, 2019

Conversation

randomanderson
Copy link
Contributor

@randomanderson randomanderson commented Dec 10, 2019

This pull request adds instrumentation to apply resource names from JAX-RS annotations when abort is called from a ContainerRequestContextFilter. There are several issues that complicate this instrumentation:

  • Getting the matched resource is implementation specific
  • Filters can be applied before a resource is matched (@PreMatching)
  • Ordering between instrumentations is not guaranteed
  • The abort method is located on the ContainerRequestContext and not the filter

To solve the above, there is:

  1. Filter instrumentation that passes the filter name from the filter to the context
  2. A default context instrumentation that creates an abort span for the prematch case using the filter name.
  3. Implementation specific context instrumentations that creates the abort span based on the JAX-RS resource annotations
  4. Context properties that adjust instrumentation behavior so that spans are updated instead of created when appropriate

@randomanderson randomanderson marked this pull request as ready for review December 10, 2019 20:15
@randomanderson randomanderson requested a review from a team as a code owner December 10, 2019 20:15
import javax.ws.rs.core.UriInfo;
import net.bytebuddy.asm.Advice;

/** Jersey specific filter instrumentation. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you comment on why implementation specific behavior was needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar reason to why connection-error-handling-jersey and connection-error-handling-resteasy exist: there's no standard JAX-RS way to get the matched resource from the context.

  • Jersey has its ExtendedUriInfo class that implements ResourceInfo
  • Resteasy has PostMatchContainerRequestContext that gives ResourceMethodInvoker
  • Apache CXF doesn't have anything 👎

I'll add some more to the javadoc

.and(named("abortWith"))
.and(takesArguments(1))
.and(takesArgument(0, named("javax.ws.rs.core.Response"))),
getClass().getName() + "$ContainerRequestContextAdvice");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever.

Copy link
Contributor

@tylerbenson tylerbenson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional comments... shame we had to break down into implementation specific integrations.

final AgentSpan parent,
final Class target,
final Method method,
final String resourceName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method seems to only be called by the overloaded version. Consider combining.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Originally, onAbort was doing something slightly different which is why I had to split out onControllerStart originally. I'll refactor it back.

@@ -0,0 +1,25 @@
muzzle {
// Cant assert fails because muzzle assumes all instrumentations will fail
// Instrumentations in jax-rs-annotations-2 will pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be able to work around this by changing the compile dependency to compileOnly.

@randomanderson randomanderson added this to the 0.39.0 milestone Dec 10, 2019
@randomanderson randomanderson merged commit 7b79a67 into master Dec 11, 2019
@randomanderson randomanderson deleted the landerson/jax-rs-filter branch December 11, 2019 15:39
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

Successfully merging this pull request may close these issues.

None yet

3 participants