Add additional classLoaderMatchers.
MODIFY
dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/AwsClientInstrumentation.java
dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/AwsClientInstrumentation.java
package datadog.trace.instrumentation.aws.v2;
+import static datadog.trace.agent.tooling.ClassLoaderMatcher.hasClassesNamed;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.implementsInterface;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
@@ -20,6 +21,12 @@ import software.amazon.awssdk.core.client.builder.SdkClientBuilder;
@AutoService(Instrumenter.class)
public final class AwsClientInstrumentation extends AbstractAwsClientInstrumentation {
+ @Override
+ public ElementMatcher<ClassLoader> classLoaderMatcher() {
+ // Optimization for expensive typeMatcher.
+ return hasClassesNamed("software.amazon.awssdk.core.client.builder.SdkClientBuilder");
+ }
+
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return nameStartsWith("software.amazon.awssdk.")

MODIFY
dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/AwsHttpClientInstrumentation.java
dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/AwsHttpClientInstrumentation.java
package datadog.trace.instrumentation.aws.v2;
+import static datadog.trace.agent.tooling.ClassLoaderMatcher.hasClassesNamed;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.extendsClass;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
@@ -25,6 +26,13 @@ import software.amazon.awssdk.core.internal.http.pipeline.stages.MakeAsyncHttpRe
@AutoService(Instrumenter.class)
public final class AwsHttpClientInstrumentation extends AbstractAwsClientInstrumentation {
+ @Override
+ public ElementMatcher<ClassLoader> classLoaderMatcher() {
+ // Optimization for expensive typeMatcher.
+ return hasClassesNamed(
+ "software.amazon.awssdk.core.internal.http.pipeline.stages.MakeHttpRequestStage");
+ }
+
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return nameStartsWith("software.amazon.awssdk.")

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/AkkaForkJoinTaskInstrumentation.java
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/AkkaForkJoinTaskInstrumentation.java
package datadog.trace.instrumentation.java.concurrent;
+import static datadog.trace.agent.tooling.ClassLoaderMatcher.hasClassesNamed;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.extendsClass;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isAbstract;
@@ -41,6 +42,12 @@ public final class AkkaForkJoinTaskInstrumentation extends Instrumenter.Default
super(AbstractExecutorInstrumentation.EXEC_NAME);
}
+ @Override
+ public ElementMatcher<ClassLoader> classLoaderMatcher() {
+ // Optimization for expensive typeMatcher.
+ return hasClassesNamed(TASK_CLASS_NAME);
+ }
+
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return extendsClass(named(TASK_CLASS_NAME));

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/ScalaForkJoinTaskInstrumentation.java
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/ScalaForkJoinTaskInstrumentation.java
package datadog.trace.instrumentation.java.concurrent;
+import static datadog.trace.agent.tooling.ClassLoaderMatcher.hasClassesNamed;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.extendsClass;
import static net.bytebuddy.matcher.ElementMatchers.isAbstract;
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -40,6 +41,12 @@ public final class ScalaForkJoinTaskInstrumentation extends Instrumenter.Default
super(AbstractExecutorInstrumentation.EXEC_NAME);
}
+ @Override
+ public ElementMatcher<ClassLoader> classLoaderMatcher() {
+ // Optimization for expensive typeMatcher.
+ return hasClassesNamed(TASK_CLASS_NAME);
+ }
+
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return extendsClass(named(TASK_CLASS_NAME));

MODIFY
dd-java-agent/instrumentation/play-ws/src/main/java/datadog/trace/instrumentation/playws/BasePlayWSClientInstrumentation.java
dd-java-agent/instrumentation/play-ws/src/main/java/datadog/trace/instrumentation/playws/BasePlayWSClientInstrumentation.java
package datadog.trace.instrumentation.playws;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.hasClassesNamed;
-import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.hasInterface;
+import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.implementsInterface;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
@@ -33,7 +33,7 @@ public abstract class BasePlayWSClientInstrumentation extends Instrumenter.Defau
// It also delegates to another AsyncHttpClient
return nameStartsWith("play.")
.<TypeDescription>and(
- hasInterface(named("play.shaded.ahc.org.asynchttpclient.AsyncHttpClient"))
+ implementsInterface(named("play.shaded.ahc.org.asynchttpclient.AsyncHttpClient"))
.and(not(named("play.api.libs.ws.ahc.cache.CachingAsyncHttpClient"))));
}

MODIFY
dd-java-agent/instrumentation/spring-webflux-5/src/main/java/datadog/trace/instrumentation/springwebflux/server/HandlerAdapterInstrumentation.java
dd-java-agent/instrumentation/spring-webflux-5/src/main/java/datadog/trace/instrumentation/springwebflux/server/HandlerAdapterInstrumentation.java
package datadog.trace.instrumentation.springwebflux.server;
+import static datadog.trace.agent.tooling.ClassLoaderMatcher.hasClassesNamed;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.implementsInterface;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isAbstract;
@@ -20,6 +21,12 @@ import net.bytebuddy.matcher.ElementMatcher;
@AutoService(Instrumenter.class)
public final class HandlerAdapterInstrumentation extends AbstractWebfluxInstrumentation {
+ @Override
+ public ElementMatcher<ClassLoader> classLoaderMatcher() {
+ // Optimization for expensive typeMatcher.
+ return hasClassesNamed("org.springframework.web.reactive.HandlerAdapter");
+ }
+
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return not(isAbstract())

MODIFY
dd-java-agent/instrumentation/spring-webflux-5/src/main/java/datadog/trace/instrumentation/springwebflux/server/RouterFunctionInstrumentation.java
dd-java-agent/instrumentation/spring-webflux-5/src/main/java/datadog/trace/instrumentation/springwebflux/server/RouterFunctionInstrumentation.java
package datadog.trace.instrumentation.springwebflux.server;
+import static datadog.trace.agent.tooling.ClassLoaderMatcher.hasClassesNamed;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.extendsClass;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isAbstract;
@@ -24,6 +25,12 @@ public final class RouterFunctionInstrumentation extends AbstractWebfluxInstrume
super("spring-webflux-functional");
}
+ @Override
+ public ElementMatcher<ClassLoader> classLoaderMatcher() {
+ // Optimization for expensive typeMatcher.
+ return hasClassesNamed("org.springframework.web.reactive.function.server.ServerRequest");
+ }
+
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return not(isAbstract())

MODIFY
dd-java-agent/instrumentation/trace-annotation/src/main/java/datadog/trace/instrumentation/trace_annotation/TraceAnnotationsInstrumentation.java
dd-java-agent/instrumentation/trace-annotation/src/main/java/datadog/trace/instrumentation/trace_annotation/TraceAnnotationsInstrumentation.java
package datadog.trace.instrumentation.trace_annotation;
+import static datadog.trace.agent.tooling.ClassLoaderMatcher.hasClassesNamed;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.safeHasSuperType;
import static datadog.trace.instrumentation.trace_annotation.TraceConfigInstrumentation.PACKAGE_CLASS_NAME_REGEX;
import static net.bytebuddy.matcher.ElementMatchers.declaresMethod;
@@ -77,6 +78,16 @@ public final class TraceAnnotationsInstrumentation extends Instrumenter.Default
this.methodTraceMatcher = methodTraceMatcher;
}
+ @Override
+ public ElementMatcher<ClassLoader> classLoaderMatcher() {
+ // Optimization for expensive typeMatcher.
+ ElementMatcher.Junction<ClassLoader> matcher = hasClassesNamed(Trace.class.getName());
+ for (final String name : additionalTraceAnnotations) {
+ matcher = matcher.or(hasClassesNamed(name));
+ }
+ return matcher;
+ }
+
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return safeHasSuperType(declaresMethod(isAnnotatedWith(methodTraceMatcher)));

MODIFY
dd-java-agent/instrumentation/trace-annotation/src/main/java/datadog/trace/instrumentation/trace_annotation/TraceConfigInstrumentation.java
dd-java-agent/instrumentation/trace-annotation/src/main/java/datadog/trace/instrumentation/trace_annotation/TraceConfigInstrumentation.java
package datadog.trace.instrumentation.trace_annotation;
+import static datadog.trace.agent.tooling.ClassLoaderMatcher.hasClassesNamed;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.safeHasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -124,6 +125,12 @@ public class TraceConfigInstrumentation implements Instrumenter {
this.methodNames = methodNames;
}
+ @Override
+ public ElementMatcher<ClassLoader> classLoaderMatcher() {
+ // Optimization for expensive typeMatcher.
+ return hasClassesNamed(className);
+ }
+
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return safeHasSuperType(named(className));

Add additional classLoaderMatchers.