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

Refactor TypeInstrumentation#transformers() method #3019

Merged

Conversation

mateuszrzeszutek
Copy link
Member

This PR was inspired by DataDog's AdviceTransformation interface introduced in DataDog/dd-trace-java#2673 (FYI @tylerbenson)

I've changed the TypeInstrumentation interface and introduced TypeTransformer:

interface TypeInstrumentation {
  // ...

  // removed the map-returning transformers()
  void transform(TypeTransformer transformer);
}

interface TypeTransformer {

  void applyAdviceToMethod(
      ElementMatcher<? super MethodDescription> methodMatcher, String adviceClassName);

  void applyTransformer(AgentBuilder.Transformer transformer);
}

This has several merits:

  • we no longer need to create those transformer maps (which I believe was the main reason for the DD change);
  • this allows us to introduce type transformations other than advices - e.g. adding the static initializer (see How to instrument static initializers? #2685)

The PR is has lots of changed files, but 98% of it is just changing all existing TypeInstrumentations. The most interesting parts are in javaagent-extension-api and javaagent-tooling.

@laurit
Copy link
Contributor

laurit commented May 17, 2021

If TypeTransformer had applyAdviceToMethod that takes class instead of className we could build a byte buddy plugin similar to MuzzleCodeGenerationPlugin that translates from class to className and calls the string version of applyAdviceToMethod.

@tylerbenson
Copy link
Member

tylerbenson commented May 17, 2021

I would suggest splitting this into at least two commits to make it easier to review. (one with the API change, another with all the instrumentation changes)

Mateusz Rzeszutek added 2 commits May 17, 2021 19:26
Add TypeInstrumentation and its implementations
Use the new method in all existing TypeInstrumentation implementations
@mateuszrzeszutek
Copy link
Member Author

I would suggest splitting this into at least two commits to make it easier to review.

That's a good idea, done. The first commit in this PR contains all the API changes, the second one is just changing all TypeInstrumentations in the project.

Copy link
Member

@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.

Much better.

@@ -30,8 +28,8 @@
}

@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
Copy link
Member

Choose a reason for hiding this comment

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

I will not miss this method signature 😂

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

Awesome!

@mateuszrzeszutek mateuszrzeszutek merged commit bb8f515 into open-telemetry:main May 18, 2021
@mateuszrzeszutek mateuszrzeszutek deleted the type-transformer branch May 18, 2021 07:50
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

5 participants