From 9def1a6001be1e8d08d982105c3c0366ebe81417 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:10:22 +0100 Subject: [PATCH] IndyProxy > InstrumentationProxy --- .../src/test/java/ReflectionTest.java | 16 +++++++++------- .../internal/reflection/ReflectionHelper.java | 6 +++--- .../v3_1/DispatcherServletInstrumentation.java | 4 ++-- .../v6_0/DispatcherServletInstrumentation.java | 4 ++-- ...{IndyProxy.java => InstrumentationProxy.java} | 2 +- ...lper.java => InstrumentationProxyHelper.java} | 8 ++++---- ....java => InstrumentationProxyHelperTest.java} | 13 +++++++------ .../instrumentation/indy/IndyProxyFactory.java | 4 ++-- .../indy/IndyProxyFactoryTest.java | 10 ++++++---- 9 files changed, 36 insertions(+), 31 deletions(-) rename javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/{IndyProxy.java => InstrumentationProxy.java} (92%) rename javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/{IndyProxyHelper.java => InstrumentationProxyHelper.java} (81%) rename javaagent-bootstrap/src/test/java/io/opentelemetry/javaagent/bootstrap/{IndyProxyHelperTest.java => InstrumentationProxyHelperTest.java} (55%) diff --git a/instrumentation/internal/internal-reflection/javaagent-integration-tests/src/test/java/ReflectionTest.java b/instrumentation/internal/internal-reflection/javaagent-integration-tests/src/test/java/ReflectionTest.java index 4b5e4ff45f06..7293136a21bb 100644 --- a/instrumentation/internal/internal-reflection/javaagent-integration-tests/src/test/java/ReflectionTest.java +++ b/instrumentation/internal/internal-reflection/javaagent-integration-tests/src/test/java/ReflectionTest.java @@ -6,7 +6,7 @@ import static org.assertj.core.api.Assertions.assertThat; import instrumentation.TestHelperClass; -import io.opentelemetry.javaagent.bootstrap.IndyProxy; +import io.opentelemetry.javaagent.bootstrap.InstrumentationProxy; import io.opentelemetry.javaagent.bootstrap.VirtualFieldAccessorMarker; import io.opentelemetry.javaagent.bootstrap.VirtualFieldInstalledMarker; import java.io.ObjectStreamClass; @@ -57,7 +57,7 @@ void testInjectedClassProxyUnwrap() throws Exception { .isNotNull(); Object instance = helperType.getConstructor().newInstance(); - if (IndyProxy.class.isAssignableFrom(helperType)) { + if (InstrumentationProxy.class.isAssignableFrom(helperType)) { // indy advice: must be an indy proxy for (Method method : helperType.getMethods()) { @@ -69,18 +69,20 @@ void testInjectedClassProxyUnwrap() throws Exception { for (Class interfaceType : helperType.getInterfaces()) { assertThat(interfaceType) .describedAs("indy proxy interface must be hidden from reflection") - .isNotEqualTo(IndyProxy.class); + .isNotEqualTo(InstrumentationProxy.class); } - assertThat(instance).isInstanceOf(IndyProxy.class); + assertThat(instance).isInstanceOf(InstrumentationProxy.class); - Object proxyDelegate = ((IndyProxy) instance).__getIndyProxyDelegate(); - assertThat(proxyDelegate).isNotInstanceOf(IndyProxy.class); + Object proxyDelegate = ((InstrumentationProxy) instance).__getIndyProxyDelegate(); + assertThat(proxyDelegate).isNotInstanceOf(InstrumentationProxy.class); } else { // inline advice: must be of the expected type assertThat(helperType).isEqualTo(TestHelperClass.class); - assertThat(instance).isInstanceOf(TestHelperClass.class).isNotInstanceOf(IndyProxy.class); + assertThat(instance) + .isInstanceOf(TestHelperClass.class) + .isNotInstanceOf(InstrumentationProxy.class); } } } diff --git a/instrumentation/internal/internal-reflection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/reflection/ReflectionHelper.java b/instrumentation/internal/internal-reflection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/reflection/ReflectionHelper.java index 78a9fb78598a..e38e67de2a71 100644 --- a/instrumentation/internal/internal-reflection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/reflection/ReflectionHelper.java +++ b/instrumentation/internal/internal-reflection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/reflection/ReflectionHelper.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.internal.reflection; -import io.opentelemetry.javaagent.bootstrap.IndyProxy; +import io.opentelemetry.javaagent.bootstrap.InstrumentationProxy; import io.opentelemetry.javaagent.bootstrap.VirtualFieldAccessorMarker; import io.opentelemetry.javaagent.bootstrap.VirtualFieldDetector; import io.opentelemetry.javaagent.bootstrap.VirtualFieldInstalledMarker; @@ -71,7 +71,7 @@ public static Class[] filterInterfaces(Class[] interfaces, Class contai // filter out virtual field marker and accessor interfaces if (interfaceClass == VirtualFieldInstalledMarker.class) { continue; - } else if (interfaceClass == IndyProxy.class) { + } else if (interfaceClass == InstrumentationProxy.class) { continue; } else if (VirtualFieldAccessorMarker.class.isAssignableFrom(interfaceClass) && interfaceClass.isSynthetic() @@ -89,6 +89,6 @@ public static Class[] filterInterfaces(Class[] interfaces, Class contai private static boolean noInterfaceToHide(Class containingClass) { return !VirtualFieldInstalledMarker.class.isAssignableFrom(containingClass) - && !IndyProxy.class.isAssignableFrom(containingClass); + && !InstrumentationProxy.class.isAssignableFrom(containingClass); } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v3_1/DispatcherServletInstrumentation.java b/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v3_1/DispatcherServletInstrumentation.java index 1b04adc3e07f..2b35744d63ed 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v3_1/DispatcherServletInstrumentation.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v3_1/DispatcherServletInstrumentation.java @@ -15,7 +15,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.javaagent.bootstrap.IndyProxyHelper; +import io.opentelemetry.javaagent.bootstrap.InstrumentationProxyHelper; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import java.util.List; @@ -68,7 +68,7 @@ public static void afterRefresh( } Object bean = springCtx.getBean("otelAutoDispatcherFilter"); OpenTelemetryHandlerMappingFilter filter = - IndyProxyHelper.unwrapIfNeeded(bean, OpenTelemetryHandlerMappingFilter.class); + InstrumentationProxyHelper.unwrapIfNeeded(bean, OpenTelemetryHandlerMappingFilter.class); filter.setHandlerMappings(handlerMappings); } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v6_0/DispatcherServletInstrumentation.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v6_0/DispatcherServletInstrumentation.java index 94057be8987c..826a1a174803 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v6_0/DispatcherServletInstrumentation.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v6_0/DispatcherServletInstrumentation.java @@ -15,7 +15,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.javaagent.bootstrap.IndyProxyHelper; +import io.opentelemetry.javaagent.bootstrap.InstrumentationProxyHelper; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import java.util.List; @@ -69,7 +69,7 @@ public static void afterRefresh( Object bean = springCtx.getBean("otelAutoDispatcherFilter"); OpenTelemetryHandlerMappingFilter filter = - IndyProxyHelper.unwrapIfNeeded(bean, OpenTelemetryHandlerMappingFilter.class); + InstrumentationProxyHelper.unwrapIfNeeded(bean, OpenTelemetryHandlerMappingFilter.class); filter.setHandlerMappings(handlerMappings); } } diff --git a/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/IndyProxy.java b/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/InstrumentationProxy.java similarity index 92% rename from javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/IndyProxy.java rename to javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/InstrumentationProxy.java index 2e664fc428e5..b92f0994dd09 100644 --- a/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/IndyProxy.java +++ b/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/InstrumentationProxy.java @@ -6,7 +6,7 @@ package io.opentelemetry.javaagent.bootstrap; /** Interface added to indy proxies to allow unwrapping the proxy object */ -public interface IndyProxy { +public interface InstrumentationProxy { /** * Unwraps the proxy delegate instance diff --git a/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/IndyProxyHelper.java b/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/InstrumentationProxyHelper.java similarity index 81% rename from javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/IndyProxyHelper.java rename to javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/InstrumentationProxyHelper.java index b7174a614ed0..2a369ab9a224 100644 --- a/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/IndyProxyHelper.java +++ b/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/InstrumentationProxyHelper.java @@ -5,9 +5,9 @@ package io.opentelemetry.javaagent.bootstrap; -public class IndyProxyHelper { +public class InstrumentationProxyHelper { - private IndyProxyHelper() {} + private InstrumentationProxyHelper() {} /** * Unwraps and casts an indy proxy, or just casts if it's not an indy proxy. @@ -21,8 +21,8 @@ private IndyProxyHelper() {} * expected type */ public static T unwrapIfNeeded(Object o, Class type) { - if (o instanceof IndyProxy) { - Object delegate = ((IndyProxy) o).__getIndyProxyDelegate(); + if (o instanceof InstrumentationProxy) { + Object delegate = ((InstrumentationProxy) o).__getIndyProxyDelegate(); if (type.isAssignableFrom(delegate.getClass())) { return type.cast(delegate); } diff --git a/javaagent-bootstrap/src/test/java/io/opentelemetry/javaagent/bootstrap/IndyProxyHelperTest.java b/javaagent-bootstrap/src/test/java/io/opentelemetry/javaagent/bootstrap/InstrumentationProxyHelperTest.java similarity index 55% rename from javaagent-bootstrap/src/test/java/io/opentelemetry/javaagent/bootstrap/IndyProxyHelperTest.java rename to javaagent-bootstrap/src/test/java/io/opentelemetry/javaagent/bootstrap/InstrumentationProxyHelperTest.java index f476d9c01b22..996e414ea857 100644 --- a/javaagent-bootstrap/src/test/java/io/opentelemetry/javaagent/bootstrap/IndyProxyHelperTest.java +++ b/javaagent-bootstrap/src/test/java/io/opentelemetry/javaagent/bootstrap/InstrumentationProxyHelperTest.java @@ -10,30 +10,31 @@ import org.junit.jupiter.api.Test; -class IndyProxyHelperTest { +class InstrumentationProxyHelperTest { @Test void wrongType() { assertThrows( - IllegalArgumentException.class, () -> IndyProxyHelper.unwrapIfNeeded("", Integer.class)); + IllegalArgumentException.class, + () -> InstrumentationProxyHelper.unwrapIfNeeded("", Integer.class)); assertThrows( IllegalArgumentException.class, - () -> IndyProxyHelper.unwrapIfNeeded(proxy(""), Integer.class)); + () -> InstrumentationProxyHelper.unwrapIfNeeded(proxy(""), Integer.class)); } @Test void unwrap() { // no wrapping - Number number = IndyProxyHelper.unwrapIfNeeded(42, Number.class); + Number number = InstrumentationProxyHelper.unwrapIfNeeded(42, Number.class); assertThat(number).isEqualTo(42); // unwrap needed - String string = IndyProxyHelper.unwrapIfNeeded(proxy("hello"), String.class); + String string = InstrumentationProxyHelper.unwrapIfNeeded(proxy("hello"), String.class); assertThat(string).isEqualTo("hello"); } - private static IndyProxy proxy(Object delegate) { + private static InstrumentationProxy proxy(Object delegate) { return () -> delegate; } } diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/IndyProxyFactory.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/IndyProxyFactory.java index bcd9e166d311..9cca710ccda8 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/IndyProxyFactory.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/IndyProxyFactory.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.tooling.instrumentation.indy; -import io.opentelemetry.javaagent.bootstrap.IndyProxy; +import io.opentelemetry.javaagent.bootstrap.InstrumentationProxy; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -96,7 +96,7 @@ public DynamicType.Unloaded generateProxy( TypeDescription classToProxy, String proxyClassName) { TypeDescription.Generic superClass = classToProxy.getSuperClass(); List interfaces = new ArrayList<>(classToProxy.getInterfaces()); - interfaces.add(TypeDescription.ForLoadedType.of(IndyProxy.class)); + interfaces.add(TypeDescription.ForLoadedType.of(InstrumentationProxy.class)); DynamicType.Builder builder = new ByteBuddy() .subclass(superClass, ConstructorStrategy.Default.NO_CONSTRUCTORS) diff --git a/javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/IndyProxyFactoryTest.java b/javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/IndyProxyFactoryTest.java index c8d09654063f..9bd9ecb78917 100644 --- a/javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/IndyProxyFactoryTest.java +++ b/javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/IndyProxyFactoryTest.java @@ -7,7 +7,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import io.opentelemetry.javaagent.bootstrap.IndyProxy; +import io.opentelemetry.javaagent.bootstrap.InstrumentationProxy; import io.opentelemetry.javaagent.tooling.instrumentation.indy.dummies.DummyAnnotation; import java.lang.invoke.CallSite; import java.lang.invoke.ConstantCallSite; @@ -329,14 +329,16 @@ void verifyNonPublicMembersIgnored() { @Test void verifyProxyClass() throws Exception { Class proxyType = generateProxy(ProxyUnwrapTest.class); - assertThat(proxyType).isNotInstanceOf(IndyProxy.class).isNotInstanceOf(ProxyUnwrapTest.class); + assertThat(proxyType) + .isNotInstanceOf(InstrumentationProxy.class) + .isNotInstanceOf(ProxyUnwrapTest.class); - assertThat(IndyProxy.class.isAssignableFrom(proxyType)) + assertThat(InstrumentationProxy.class.isAssignableFrom(proxyType)) .describedAs("proxy class can be cast to IndyProxy") .isTrue(); Object proxyInstance = proxyType.getConstructor().newInstance(); - Object proxyDelegate = ((IndyProxy) proxyInstance).__getIndyProxyDelegate(); + Object proxyDelegate = ((InstrumentationProxy) proxyInstance).__getIndyProxyDelegate(); assertThat(proxyDelegate).isInstanceOf(ProxyUnwrapTest.class); }