Match classloader when applying netty instrumentation.
MODIFY
instrumentation/netty/netty-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_0/NettyInstrumentationModule.java
instrumentation/netty/netty-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_0/NettyInstrumentationModule.java
package io.opentelemetry.javaagent.instrumentation.netty.v4_0;
+import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.ClassLoaderMatcher.hasClassesNamed;
import static java.util.Arrays.asList;
+import static net.bytebuddy.matcher.ElementMatchers.not;
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
import java.util.List;
+import net.bytebuddy.matcher.ElementMatcher;
@AutoService(InstrumentationModule.class)
public class NettyInstrumentationModule extends InstrumentationModule {
@@ -18,6 +21,13 @@ public class NettyInstrumentationModule extends InstrumentationModule {
super("netty", "netty-4.0");
}
+ @Override
+ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
+ // Class added in 4.1.0 and not in 4.0.56 to avoid resolving this instrumentation completely
+ // when using 4.1.
+ return not(hasClassesNamed("io.netty.handler.codec.http.CombinedHttpHeaders"));
+ }
+
@Override
public List<TypeInstrumentation> typeInstrumentations() {
return asList(

MODIFY
instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyInstrumentationModule.java
instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyInstrumentationModule.java
package io.opentelemetry.javaagent.instrumentation.netty.v4_1;
+import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.ClassLoaderMatcher.hasClassesNamed;
import static java.util.Arrays.asList;
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
import java.util.List;
+import net.bytebuddy.matcher.ElementMatcher;
@AutoService(InstrumentationModule.class)
public class NettyInstrumentationModule extends InstrumentationModule {
@@ -18,6 +20,13 @@ public class NettyInstrumentationModule extends InstrumentationModule {
super("netty", "netty-4.1");
}
+ @Override
+ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
+ // Class added in 4.1.0 and not in 4.0.56 to avoid resolving this instrumentation completely
+ // when using 4.0.
+ return hasClassesNamed("io.netty.handler.codec.http.CombinedHttpHeaders");
+ }
+
@Override
public List<TypeInstrumentation> typeInstrumentations() {
return asList(

Match classloader when applying netty instrumentation. (#2099)