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

Weaver is dependent on jax-rs instrumentation module classes being read from the module jar in a specific order #233

Closed
jasonjkeller opened this issue Mar 2, 2021 · 1 comment · Fixed by #232 or #234
Assignees
Labels
bug Something isn't working as designed/intended

Comments

@jasonjkeller
Copy link
Contributor

jasonjkeller commented Mar 2, 2021

The weaver loads & caches each instrumentation module in CachedWeavePackage.load by locating the instrumentation module jar and reading in the bytes for the all of the classes contained in the module.

It appears that the weaver depends on the classes being read in from the JarInputStream from the jar (newrelic.jar!/instrumentation/jax-rs-1.0-1.0.jar) in a specific and predictable order for the jax-rs-1.0 instrumentation.

Specifically, the JavaxWsRsApi_Instrumentation class needs to be read in before JavaxWsRsApi_Subresource_Instrumentation or the instrumentation will fail to apply with a WeaveViolation (see CLASS_MISSING_REQUIRED_ANNOTATIONS) in cases where jax-rs sub-resources are being used and do not include the @Path annotation.

The reason is that a map of all method annotations is updated in WeavePackage.processWeaveBytes when each of the classes mentioned above are processed. In the map (Map<String, ClassNode>) annotations are mapped to a weaveNode (either JavaxWsRsApi_Instrumentation or JavaxWsRsApi_Subresource_Instrumentation).

As it currently works JavaxWsRsApi_Subresource_Instrumentation needs to be processed last so that it replaces the weaveNode values in the map for the sub-resource instrumentation to work properly.

As it stands, this approach is brittle and subject to breaking because there is no guarantee that the classes will be added and read from the jax-rs-1.0-1.0.jar in a deterministic manner given that the build process can vary depending on the environment that it is run in.

@jasonjkeller jasonjkeller added the bug Something isn't working as designed/intended label Mar 2, 2021
@jasonjkeller jasonjkeller linked a pull request Mar 3, 2021 that will close this issue
@jasonjkeller
Copy link
Contributor Author

This PR forces gradle to build the instrumentation jars in a deterministic manner that fixes the issue.
#232

However it would be ideal if the weaver didn't depend on such things.

@jasonjkeller jasonjkeller self-assigned this Mar 3, 2021
@jasonjkeller jasonjkeller linked a pull request Mar 4, 2021 that will close this issue
@jasonjkeller jasonjkeller reopened this Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as designed/intended
Projects
Archived in project
1 participant