-
Notifications
You must be signed in to change notification settings - Fork 291
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
Do not transform Mockito-generated classes #7048
Do not transform Mockito-generated classes #7048
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CombiningTransformerBuilder
is not the place to add this kind of exclusion because it will degrade performance by adding an extra check on the name for everything - even when we already know the class doesn't start with that package.
Since you want to exclude everything under a package the simplest way is to add it to https://github.com/DataDog/dd-trace-java/blob/master/dd-java-agent/agent-tooling/src/main/resources/datadog/trace/agent/tooling/bytebuddy/matcher/ignored_class_name.trie where we maintain a list of packages and classes to ignore for performance reasons (because we know they are uninteresting) or they should never be instrumented because it would break things.
You should just need to add:
1 org.mockito.codegen.*
Note if you wanted to exclude generated/proxy classes which didn't have a common package, but had another recognizable token in their name then you can do that in https://github.com/DataDog/dd-trace-java/blob/master/dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/bytebuddy/matcher/ProxyClassIgnores.java
cdfde4e
to
b953a7f
Compare
...ing/src/main/resources/datadog/trace/agent/tooling/bytebuddy/matcher/ignored_class_name.trie
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
What Does This Do
Adds the common package for Mockito-generated classes to the list of global ignores.
Motivation
Whenever a class is mocked with Mockito, a new class is generated that replaces the original class' methods with the mocked ones.
If the tracer contains instrumentations that transform the original class, the same instrumentations will most likely be applied to the mocked class as it extends the original one.
Transforming the mocked class' code leads to errors: some instrumentations, when executed a transformed method, call another method of the same instance. Mockito does not handle this well: if a mocked method is called from inside another mocked method, Mockito's internal state gets corrupted.
The solution is to avoid transforming Mockito-generated classes, both because it fixes the errors and because tracing mock methods makes little sense.
Jira ticket: CIVIS-10060