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

make servlet3 + spring webmvc + jaxrs 2.0 indy compatible #12432

Open
wants to merge 43 commits into
base: main
Choose a base branch
from

Conversation

SylvainJuge
Copy link
Contributor

@SylvainJuge SylvainJuge commented Oct 10, 2024

part of #11457

Introduces IndyProxy interface for the classes that are injected into instrumented classes classloader which allows to transparently unwrap the proxy delegate when needed with IndyProxyHelper. This interface and its only method is hidden from the reflection API.

@SylvainJuge SylvainJuge mentioned this pull request Oct 10, 2024
36 tasks
@SylvainJuge SylvainJuge changed the title make servlet3 indy compatible make servlet3 + spring webmvc indy compatible Oct 10, 2024
@SylvainJuge SylvainJuge marked this pull request as ready for review October 29, 2024 09:27
@SylvainJuge SylvainJuge requested a review from a team as a code owner October 29, 2024 09:27
@SylvainJuge SylvainJuge changed the title make servlet3 + spring webmvc indy compatible make servlet3 + spring webmvc + jaxrs 2.0 indy compatible Oct 29, 2024
if (bean instanceof OpenTelemetryHandlerMappingFilter) {
// inline advice: no proxy class is used
filter = (OpenTelemetryHandlerMappingFilter) bean;
} else {
Copy link
Contributor

@laurit laurit Nov 12, 2024

Choose a reason for hiding this comment

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

Imo instead of doing the reflection here there should be an API to do this. Something that would unwrap the object when it is proxy and return the input when it is not. So you could write OpenTelemetryHandlerMappingFilter filter = = (OpenTelemetryHandlerMappingFilter) unwrap(springCtx.getBean("otelAutoDispatcherFilter"));
I guess using the reflection as currently is fine for start. Instead of making the delegate field public I'd probably try to make the proxy instance implement an interface that allow unwrapping. If needed that interface could be hidden from reflection

Idk how hard all of this would be to implement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, I've managed to implement this by introducing an IndyProxy interface that allows us to easily unwrap the proxies when needed with an IndyProxyHelper class. It took me a while and it's definitely a bit more complicated than a public field, but it's way more elegant to use. Also it was a very good way to learn about "how to hide things from reflection API" :-).

Let me know if that's close to what you had in mind here. One thing that is still missing though is properly testing hiding proxy method and interface in the reflection instrumentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update: tests have been added so it should be ready for review now.

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.

5 participants