-
Notifications
You must be signed in to change notification settings - Fork 864
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
base: main
Are you sure you want to change the base?
Conversation
...telemetry/javaagent/instrumentation/springweb/v3_1/WebApplicationContextInstrumentation.java
Outdated
Show resolved
Hide resolved
…nstrumentation into indy-servlet3
…nstrumentation into indy-servlet3
…nstrumentation into indy-servlet3
...telemetry/javaagent/instrumentation/spring/webmvc/v3_1/DispatcherServletInstrumentation.java
Outdated
Show resolved
Hide resolved
...telemetry/javaagent/instrumentation/spring/webmvc/v6_0/DispatcherServletInstrumentation.java
Outdated
Show resolved
Hide resolved
…nstrumentation into indy-servlet3
...telemetry/javaagent/instrumentation/spring/webmvc/v3_1/DispatcherServletInstrumentation.java
Outdated
Show resolved
Hide resolved
...main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsInstrumentationModule.java
Outdated
Show resolved
Hide resolved
…nstrumentation into indy-servlet3
…nstrumentation into indy-servlet3
...o/opentelemetry/javaagent/instrumentation/springweb/v3_1/SpringWebInstrumentationModule.java
Show resolved
Hide resolved
if (bean instanceof OpenTelemetryHandlerMappingFilter) { | ||
// inline advice: no proxy class is used | ||
filter = (OpenTelemetryHandlerMappingFilter) bean; | ||
} else { |
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.
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
Line 59 in 647fc45
public static Class<?>[] filterInterfaces(Class<?>[] interfaces, Class<?> containingClass) { |
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.
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.
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.
Update: tests have been added so it should be ready for review now.
…nstrumentation into indy-servlet3
…nstrumentation into indy-servlet3
…nstrumentation into indy-servlet3
…nstrumentation into indy-servlet3
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 withIndyProxyHelper
. This interface and its only method is hidden from the reflection API.