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

WeavedMethod annotation on constructor #1153

Closed
thiagosardinha opened this issue Feb 14, 2023 · 5 comments · Fixed by #1162
Closed

WeavedMethod annotation on constructor #1153

thiagosardinha opened this issue Feb 14, 2023 · 5 comments · Fixed by #1162
Assignees
Labels
bug Something isn't working as designed/intended on-roadmap Issue has been added to our product roadmap and will be worked in the coming quarter

Comments

@thiagosardinha
Copy link

I have a Java 11 application with Dropwizard framework that implements some Quartz jobs.

After bumping Dropwizard's version from 2.1.1 to 2.1.4 the application stopped working when using the New Relic Java agent (tested with versions 7.10.0 and 8.0.0). After a lot of debugging, I tracked down that Dropwizard's new version changed its proxy implementation from javassist to bytebuddy and the latter has a validation that does not allow elements with annotations that don't target it.

Problem is, New Relic Java agent annotates my Quartz jobs implementations' constructors with the @WeaveMethod annotation, which bytebuddy considers illegal state since the annotation targets only methods. This is where it fails.

It's so many moving parts that I'm not even sure the issue is here, but seems that bytebuddy's validation sort of makes sense, so here I am.

Note, the job classes are also annotated with the @InstrumentedMethod annotation, which I assume would fail as well.

Expected Behavior

Maybe include constructors as target in the @WeaveMethod annotation. Or use another annotation specific for constructors so targets are correct for the included annotations.

Troubleshooting or NR Diag results

Exception that is raised by bytebuddy in this validation

java.lang.IllegalStateException: Cannot add @com.newrelic.agent.instrumentation.WeavedMethod(source={"com.newrelic.instrumentation.quartz-2.0.0"}) on public test.SomeImplementationOfQuartzJob$ByteBuddy$CLCWj0h4(java.util.Optional)
	at net.bytebuddy.dynamic.scaffold.InstrumentedType$Default.validated(InstrumentedType.java:1793)

debugging the bytebuddy shows the included annotations
WhatsApp Image 2023-02-14 at 18 28 12
validation

annotated class snippet

import org.quartz.Job;

import java.util.Optional;

public class SomeImplementationOfQuartzJob implements Job {

    private final Optional<MetricsReporter> metricsReporter;

    public SomeImplementationOfQuartzJob(Optional<MetricsReporter> metricsReporter)
    {
        this.metricsReporter = metricsReporter;
    }

    // ...
}

metrics reporters is just a wrapper to new relic

public class MetricsReporter {

    private static final String NEW_RELIC_TRANSACTION_NAME_PREFIX = "/";

    public void reportTransaction(String category, String transactionName) {
        NewRelic.setTransactionName(category, NEW_RELIC_TRANSACTION_NAME_PREFIX + transactionName);
    }

    public void reportCustomEvent(String eventName, Map<String, Object> customParams) {
        NewRelic.getAgent().getInsights().recordCustomEvent(eventName, customParams);
    }

    public void reportTransaction(String category, String transactionName, Map<String, String> customParams) {
        NewRelic.setTransactionName(category, NEW_RELIC_TRANSACTION_NAME_PREFIX + transactionName);

        customParams.forEach(NewRelic::addCustomParameter);
    }
}

Steps to Reproduce

as I said, started happening to me after bumping Dropwizard's version to 2.1.4, but that's just because they switched from using javassist to bytebuddy which has the validation I mentioned.

Basically, using NR java agent in an Dropwizard 2.1.4 application with a class implementing org.quartz.Job.

Your Environment

  • Ubuntu 22.04 - also happened in AWS Fargate
  • Dropwizard 2.1.4 - or just bytebuddy 1.12.9 and 1.12.18 were tested
  • New Relic Java agent 7.10.0 or 8.0.0
  • Happened in classes that implemented Quartz jobs - quartz-scheduler 2.3.2
  • Java 11
openjdk version "11.0.14.1" 2022-02-08 LTS
OpenJDK Runtime Environment Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS, mixed mode)

Additional context

More details on Dropwizard's change to bytebuddy: dropwizard/dropwizard#5748

@thiagosardinha thiagosardinha added the bug Something isn't working as designed/intended label Feb 14, 2023
@workato-integration
Copy link

@meiao
Copy link
Contributor

meiao commented Feb 14, 2023

Hi @thiagosardinha,
thanks for the investigation.
Could you test a custom agent to see if it fixes this problem?

It is being generated now and should be available in a few minutes at:
https://github.com/newrelic/newrelic-java-agent/actions/runs/4178835318
As soon as it is ready, in that page, under "Artifacts" there will be an entry "custom-newrelic-jar" which is a zip file containing the agent jar.

@thiagosardinha
Copy link
Author

Hi @meiao. Thanks for the quick response!

Tested the custom jar and seems to have worked for @WeavedMethod, but got the same error for @InstrumentedMethod:

java.lang.IllegalStateException: Cannot add @com.newrelic.agent.instrumentation.InstrumentedMethod(dispatcher=false, instrumentationTypes={WeaveInstrumentation}, instrumentationNames={"com.newrelic.instrumentation.quartz-2.0.0"})  on public test.SomeImplementationOfQuartzJob$ByteBuddy$CLCWj0h4(java.util.Optional)
	at net.bytebuddy.dynamic.scaffold.InstrumentedType$Default.validated(InstrumentedType.java:1793)

My guess is the same fix would have to be applied to it too.

@meiao
Copy link
Contributor

meiao commented Feb 15, 2023

Sorry, I overlooked your comment at the bottom about @InstrumentedMethod.
Another custom jar is building, can soon be retrieved at https://github.com/newrelic/newrelic-java-agent/actions/runs/4185251493

@thiagosardinha
Copy link
Author

That worked! Thanks!

@kford-newrelic kford-newrelic added the on-roadmap Issue has been added to our product roadmap and will be worked in the coming quarter label Feb 28, 2023
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 on-roadmap Issue has been added to our product roadmap and will be worked in the coming quarter
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants