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

indy instrumentation - leftovers migration #13074

Merged
merged 26 commits into from
Jan 31, 2025

Conversation

SylvainJuge
Copy link
Contributor

@SylvainJuge SylvainJuge commented Jan 20, 2025

Should be the final step of #11457, hopefully completing it.

There are currently 5 overrides of isIndyModule() and the goal here is to remove all most of them, hence allowing to move forward with the next steps described in #13031

@SylvainJuge SylvainJuge mentioned this pull request Jan 21, 2025
36 tasks
@SylvainJuge SylvainJuge marked this pull request as ready for review January 21, 2025 15:10
@SylvainJuge SylvainJuge requested a review from a team as a code owner January 21, 2025 15:10
}

@Override
public byte[] transform(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[for reviewer] here we override the pre-java9 API and then resolve the class module from the class, this allows to transparently call it from code compiled with Java 8 API level.

In practice, there is only a single usage for this in the internal lambda instrumentation, which makes it equivalent to the (now removed) Java9LambdaTransformer.

instrumentationInstalled = true;
ClassFileTransformerHolder.setClassFileTransformer(resettableClassFileTransformer);
if (JavaModule.isSupported()) {
// wrapping in a JPMS compliant implementation
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[for reviewer] wrapping at registration time helps to make the consumer transparently use it with java 8 API.

public class InlineIbmResourceLevelInstrumentationModule extends InstrumentationModule {
public InlineIbmResourceLevelInstrumentationModule() {
super("inline-ibm-resource-level");
public class IbmResourceLevelInstrumentationModule extends InstrumentationModule {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[for reviewer] there is no need to maintain an inline and indy variants of this instrumentation, so we only need one that is compatible with both.

@SylvainJuge SylvainJuge marked this pull request as draft January 22, 2025 15:08
*
* @return class transformer for defining lambdas
*/
public static ClassFileTransformer getLambdaClassFileTransformer() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[for reviewer] this is only used for lambda, and the ClassFileTransformer instances that are used here are very specific to lambda instrumentation, so renaming helps keep it clear.

@SylvainJuge SylvainJuge marked this pull request as ready for review January 23, 2025 10:17
// to get a reference to the jpms module. However, a null value must be passed to the
// underlying transformer as this code is called when the lambda is defined.
byte[] result =
transformer.transform(
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't immediately get why you wanted to change this, but I guess it is to reduce the helper classes and push more logic into the agent code. I think this is good idea and getting rid for the extra module for java9 is nice. What I'd change is that I'd probably also rename ClassFileTransformerHolder as it is only for lambdas as you noted. Also I'd consider not using ClassFileTransformer here. Passing the targetClass argument to the transform method confused me a bit as transform should have the class there only when retransforming/redefining which we aren't doing here. You could have an interface in ClassFileTransformerHolder that takes the necessary arguments. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree on the ClassFileTransformerHolder rename as it's definitely only used for lambdas.

I initially tried to simplify the design/API but that requires to introduce a new interface, so I thought maybe keep reusing ClassFileTransformer could be an acceptable compromise, but I agree that it might be a bit confusing as the implementations details leak into the callers as shown by the quantity of comments to use it the way it's intended.

I'll do another attempt by introducing a new interface to see if it helps improve this.

@trask trask merged commit ca3c685 into open-telemetry:main Jan 31, 2025
58 checks passed
@trask
Copy link
Member

trask commented Jan 31, 2025

thanks @SylvainJuge @laurit!

@SylvainJuge SylvainJuge deleted the indy-leftovers branch January 31, 2025 15:54
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.

4 participants