Avoid calling superclass matcher where possible
Saves about 100ms of startup time on test app
MODIFY
dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/RequestInstrumentation.java
dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/RequestInstrumentation.java
@@ -2,6 +2,7 @@ package datadog.trace.instrumentation.aws.v0;
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeExtendsClass;
import static java.util.Collections.singletonMap;
+import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -26,7 +27,8 @@ public final class RequestInstrumentation extends Instrumenter.Default {
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
- return safeExtendsClass(named("com.amazonaws.AmazonWebServiceRequest"));
+ return nameStartsWith("com.amazonaws.")
+ .and(safeExtendsClass(named("com.amazonaws.AmazonWebServiceRequest")));
}
@Override

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
@@ -5,6 +5,7 @@ import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
+import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
@@ -23,7 +24,8 @@ public final class AwsClientInstrumentation extends AbstractAwsClientInstrumenta
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
- return not(isInterface())
+ return nameStartsWith("software.amazon.awssdk.")
+ .and(not(isInterface()))
.and(
safeHasInterface(named("software.amazon.awssdk.core.client.builder.SdkClientBuilder")));
}

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
@@ -5,6 +5,7 @@ import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScop
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
+import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
@@ -28,11 +29,14 @@ public final class AwsHttpClientInstrumentation extends AbstractAwsClientInstrum
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
- return safeExtendsClass(
- named("software.amazon.awssdk.core.internal.http.pipeline.stages.MakeHttpRequestStage")
+ return nameStartsWith("software.amazon.awssdk.")
+ .and(
+ safeExtendsClass(
+ named(
+ "software.amazon.awssdk.core.internal.http.pipeline.stages.MakeHttpRequestStage")
.or(
named(
- "software.amazon.awssdk.core.internal.http.pipeline.stages.MakeAsyncHttpRequestStage")))
+ "software.amazon.awssdk.core.internal.http.pipeline.stages.MakeAsyncHttpRequestStage"))))
.and(not(isInterface()));
}

MODIFY
dd-java-agent/instrumentation/couchbase-2.6/src/main/java/datadog/trace/instrumentation/couchbase/client/CouchbaseNetworkInstrumentation.java
dd-java-agent/instrumentation/couchbase-2.6/src/main/java/datadog/trace/instrumentation/couchbase/client/CouchbaseNetworkInstrumentation.java
@@ -3,6 +3,7 @@ package datadog.trace.instrumentation.couchbase.client;
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeExtendsClass;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
+import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
@@ -31,7 +32,9 @@ public class CouchbaseNetworkInstrumentation extends Instrumenter.Default {
@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
// Exact class because private fields are used
- return safeExtendsClass(named("com.couchbase.client.core.endpoint.AbstractGenericHandler"));
+ return nameStartsWith("com.couchbase.client.")
+ .<TypeDescription>and(
+ safeExtendsClass(named("com.couchbase.client.core.endpoint.AbstractGenericHandler")));
}
@Override

MODIFY
dd-java-agent/instrumentation/finatra-2.9/src/main/java/datadog/trace/instrumentation/finatra/FinatraInstrumentation.java
dd-java-agent/instrumentation/finatra-2.9/src/main/java/datadog/trace/instrumentation/finatra/FinatraInstrumentation.java
@@ -8,6 +8,7 @@ import static datadog.trace.instrumentation.finatra.FinatraDecorator.DECORATE;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
+import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -51,7 +52,8 @@ public class FinatraInstrumentation extends Instrumenter.Default {
@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
- return not(isInterface())
+ return nameStartsWith("com.twitter.finatra.")
+ .and(not(isInterface()))
.and(safeExtendsClass(named("com.twitter.finatra.http.internal.routing.Route")));
}

MODIFY
dd-java-agent/instrumentation/http-url-connection/src/main/java/datadog/trace/instrumentation/http_url_connection/HttpUrlConnectionInstrumentation.java
dd-java-agent/instrumentation/http-url-connection/src/main/java/datadog/trace/instrumentation/http_url_connection/HttpUrlConnectionInstrumentation.java
@@ -9,6 +9,7 @@ import static datadog.trace.instrumentation.http_url_connection.HttpUrlConnectio
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
+import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
@@ -25,6 +26,7 @@ import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
+import net.bytebuddy.matcher.ElementMatchers;
@AutoService(Instrumenter.class)
public class HttpUrlConnectionInstrumentation extends Instrumenter.Default {
@@ -35,8 +37,10 @@ public class HttpUrlConnectionInstrumentation extends Instrumenter.Default {
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
+ return nameStartsWith("java.net.")
+ .or(ElementMatchers.<TypeDescription>nameStartsWith("sun.net"))
// This class is a simple delegator. Skip because it does not update its `connected` field.
- return not(named("sun.net.www.protocol.https.HttpsURLConnectionImpl"))
+ .and(not(named("sun.net.www.protocol.https.HttpsURLConnectionImpl")))
.and(safeExtendsClass(named("java.net.HttpURLConnection")));
}

MODIFY
dd-java-agent/instrumentation/http-url-connection/src/main/java/datadog/trace/instrumentation/http_url_connection/UrlInstrumentation.java
dd-java-agent/instrumentation/http-url-connection/src/main/java/datadog/trace/instrumentation/http_url_connection/UrlInstrumentation.java
@@ -3,7 +3,10 @@ package datadog.trace.instrumentation.http_url_connection;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static java.util.Collections.singletonMap;
-import static net.bytebuddy.matcher.ElementMatchers.*;
+import static net.bytebuddy.matcher.ElementMatchers.is;
+import static net.bytebuddy.matcher.ElementMatchers.isMethod;
+import static net.bytebuddy.matcher.ElementMatchers.isPublic;
+import static net.bytebuddy.matcher.ElementMatchers.named;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;

MODIFY
dd-java-agent/instrumentation/play-ws-1/src/main/java/datadog/trace/instrumentation/playws1/PlayWSClientInstrumentation.java
dd-java-agent/instrumentation/play-ws-1/src/main/java/datadog/trace/instrumentation/playws1/PlayWSClientInstrumentation.java
@@ -7,6 +7,7 @@ import static datadog.trace.instrumentation.playws1.HeadersInjectAdapter.SETTER;
import static datadog.trace.instrumentation.playws1.PlayWSClientDecorator.DECORATE;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
+import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -33,8 +34,10 @@ public class PlayWSClientInstrumentation extends Instrumenter.Default {
public ElementMatcher<? super TypeDescription> typeMatcher() {
// CachingAsyncHttpClient rejects overrides to AsyncHandler
// It also delegates to another AsyncHttpClient
- return safeHasInterface(named("play.shaded.ahc.org.asynchttpclient.AsyncHttpClient"))
- .and(not(named("play.api.libs.ws.ahc.cache.CachingAsyncHttpClient")));
+ return nameStartsWith("play.")
+ .<TypeDescription>and(
+ safeHasInterface(named("play.shaded.ahc.org.asynchttpclient.AsyncHttpClient"))
+ .and(not(named("play.api.libs.ws.ahc.cache.CachingAsyncHttpClient"))));
}
@Override

MODIFY
dd-java-agent/instrumentation/ratpack-1.4/src/main/java/datadog/trace/instrumentation/ratpack/ContinuationInstrumentation.java
dd-java-agent/instrumentation/ratpack-1.4/src/main/java/datadog/trace/instrumentation/ratpack/ContinuationInstrumentation.java
@@ -3,6 +3,7 @@ package datadog.trace.instrumentation.ratpack;
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasInterface;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static java.util.Collections.singletonMap;
+import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -25,7 +26,8 @@ public final class ContinuationInstrumentation extends Instrumenter.Default {
@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
- return safeHasInterface(named("ratpack.exec.internal.Continuation"));
+ return nameStartsWith("ratpack.exec.")
+ .<TypeDescription>and(safeHasInterface(named("ratpack.exec.internal.Continuation")));
}
@Override

Avoid calling superclass matcher where possible

Saves about 100ms of startup time on test app