Skip to content

Commit 4855626

Browse files
authored
Remove forcing dynamic typing from advice (#13591)
1 parent 6521fc8 commit 4855626

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

instrumentation/netty/netty-common-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4/common/NettyFutureInstrumentation.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
99
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
10-
import static net.bytebuddy.matcher.ElementMatchers.isArray;
1110
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
1211
import static net.bytebuddy.matcher.ElementMatchers.named;
1312
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -43,15 +42,19 @@ public void transform(TypeTransformer transformer) {
4342
.and(takesArgument(0, named("io.netty.util.concurrent.GenericFutureListener"))),
4443
NettyFutureInstrumentation.class.getName() + "$AddListenerAdvice");
4544
transformer.applyAdviceToMethod(
46-
isMethod().and(named("addListeners")).and(takesArgument(0, isArray())),
45+
isMethod()
46+
.and(named("addListeners"))
47+
.and(takesArgument(0, named("io.netty.util.concurrent.GenericFutureListener[]"))),
4748
NettyFutureInstrumentation.class.getName() + "$AddListenersAdvice");
4849
transformer.applyAdviceToMethod(
4950
isMethod()
5051
.and(named("removeListener"))
5152
.and(takesArgument(0, named("io.netty.util.concurrent.GenericFutureListener"))),
5253
NettyFutureInstrumentation.class.getName() + "$RemoveListenerAdvice");
5354
transformer.applyAdviceToMethod(
54-
isMethod().and(named("removeListeners")).and(takesArgument(0, isArray())),
55+
isMethod()
56+
.and(named("removeListeners"))
57+
.and(takesArgument(0, named("io.netty.util.concurrent.GenericFutureListener[]"))),
5558
NettyFutureInstrumentation.class.getName() + "$RemoveListenersAdvice");
5659
}
5760

@@ -81,7 +84,7 @@ public static class AddListenersAdvice {
8184
@Advice.OnMethodEnter
8285
@Advice.AssignReturned.AsScalar
8386
@Advice.AssignReturned.ToArguments(@ToArgument(0))
84-
public static Object[] wrapListener(
87+
public static GenericFutureListener<?>[] wrapListener(
8588
@Advice.Argument(value = 0) GenericFutureListener<? extends Future<?>>[] listeners) {
8689

8790
Context context = Java8BytecodeBridge.currentContext();
@@ -119,7 +122,7 @@ public static class RemoveListenersAdvice {
119122
@Advice.OnMethodEnter
120123
@Advice.AssignReturned.AsScalar
121124
@Advice.AssignReturned.ToArguments(@ToArgument(0))
122-
public static Object[] wrapListener(
125+
public static GenericFutureListener<?>[] wrapListener(
123126
@Advice.Argument(value = 0) GenericFutureListener<? extends Future<?>>[] listeners) {
124127

125128
@SuppressWarnings({"unchecked", "rawtypes"})

instrumentation/pekko/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/client/HttpExtClientInstrumentation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import net.bytebuddy.asm.Advice;
1919
import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument;
2020
import net.bytebuddy.description.type.TypeDescription;
21+
import net.bytebuddy.implementation.bytecode.assign.Assigner;
2122
import net.bytebuddy.matcher.ElementMatcher;
2223
import org.apache.pekko.http.scaladsl.HttpExt;
2324
import org.apache.pekko.http.scaladsl.model.HttpRequest;
@@ -40,7 +41,8 @@ public void transform(TypeTransformer transformer) {
4041

4142
@SuppressWarnings("unused")
4243
public static class SingleRequestAdvice {
43-
@Advice.AssignReturned.ToArguments(@ToArgument(value = 0, index = 0))
44+
@Advice.AssignReturned.ToArguments(
45+
@ToArgument(value = 0, index = 0, typing = Assigner.Typing.DYNAMIC))
4446
@Advice.OnMethodEnter(suppress = Throwable.class)
4547
public static Object[] methodEnter(@Advice.Argument(value = 0) HttpRequest request) {
4648
Context parentContext = currentContext();

instrumentation/ratpack/ratpack-1.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/v1_7/DefaultExecControllerInstrumentation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public static class ConstructorAdvice {
8181
@ToField(value = "initializers", index = 0),
8282
@ToField(value = "interceptors", index = 1)
8383
})
84-
public static Object[] exit(
84+
public static ImmutableList<?>[] exit(
8585
@Advice.FieldValue("initializers") ImmutableList<? extends ExecInitializer> initializers,
8686
@Advice.FieldValue("interceptors") ImmutableList<? extends ExecInterceptor> interceptors) {
87-
return new Object[] {
87+
return new ImmutableList<?>[] {
8888
ImmutableList.of(OpenTelemetryExecInitializer.INSTANCE),
8989
ImmutableList.of(OpenTelemetryExecInterceptor.INSTANCE)
9090
};

instrumentation/ratpack/ratpack-1.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/v1_7/RequestActionSupportInstrumentation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static class ConnectDownstreamAdvice {
6363

6464
@Advice.OnMethodEnter(suppress = Throwable.class)
6565
@Advice.AssignReturned.ToArguments(@ToArgument(0))
66-
public static Object wrapDownstream(@Advice.Argument(0) Downstream<?> downstream) {
66+
public static Downstream<?> wrapDownstream(@Advice.Argument(0) Downstream<?> downstream) {
6767
// Propagate the current context to downstream
6868
// since that is the subsequent code chained to the http client call
6969
return DownstreamWrapper.wrapIfNeeded(downstream);

javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/TypeTransformerImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
99
import io.opentelemetry.javaagent.tooling.Utils;
1010
import io.opentelemetry.javaagent.tooling.bytebuddy.ExceptionHandlers;
11-
import io.opentelemetry.javaagent.tooling.instrumentation.indy.ForceDynamicallyTypedAssignReturnedFactory;
1211
import net.bytebuddy.agent.builder.AgentBuilder;
1312
import net.bytebuddy.asm.Advice;
1413
import net.bytebuddy.description.method.MethodDescription;
@@ -22,9 +21,7 @@ final class TypeTransformerImpl implements TypeTransformer {
2221
this.agentBuilder = agentBuilder;
2322
adviceMapping =
2423
Advice.withCustomMapping()
25-
.with(
26-
new ForceDynamicallyTypedAssignReturnedFactory(
27-
new Advice.AssignReturned.Factory().withSuppressed(Throwable.class)));
24+
.with(new Advice.AssignReturned.Factory().withSuppressed(Throwable.class));
2825
}
2926

3027
@Override

0 commit comments

Comments
 (0)