Correctly look for classes to determine minimum ratpack version
MODIFY
dd-java-agent/instrumentation/ratpack-1.4/ratpack-1.4.gradle
dd-java-agent/instrumentation/ratpack-1.4/ratpack-1.4.gradle
@@ -5,27 +5,7 @@ versionScan {
module = 'ratpack'
versions = "[1.4.0,)"
verifyPresent = [
- "ratpack.exec.ExecStarter" : null,
- "ratpack.exec.Execution" : null,
- "ratpack.exec.Promise" : null,
- "ratpack.exec.Result" : null,
- "ratpack.func.Action" : null,
- "ratpack.func.Function" : null,
- "ratpack.handling.Context" : null,
- "ratpack.handling.Handler" : null,
- "ratpack.handling.HandlerDecorator" : null,
- "ratpack.http.HttpMethod" : null,
- "ratpack.http.MutableHeaders" : null,
- "ratpack.http.Request" : null,
- "ratpack.http.Status" : null,
- "ratpack.http.client.HttpClient" : null,
- "ratpack.http.client.ReceivedResponse" : null,
- "ratpack.http.client.RequestSpec" : null,
- "ratpack.http.client.StreamedResponse" : null,
"ratpack.path.PathBinding": "getDescription",
- "ratpack.registry.Registry" : null,
- "ratpack.registry.RegistrySpec" : null,
- "ratpack.server.internal.ServerRegistry": "buildBaseRegistry"
]
}

MODIFY
dd-java-agent/instrumentation/ratpack-1.4/src/main/java/datadog/trace/instrumentation/ratpack/RatpackHttpClientInstrumentation.java
dd-java-agent/instrumentation/ratpack-1.4/src/main/java/datadog/trace/instrumentation/ratpack/RatpackHttpClientInstrumentation.java
package datadog.trace.instrumentation.ratpack;
-import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static datadog.trace.instrumentation.ratpack.RatpackInstrumentation.ACTION_TYPE_DESCRIPTION;
+import static datadog.trace.instrumentation.ratpack.RatpackInstrumentation.CLASSLOADER_CONTAINS_RATPACK_1_4_OR_ABOVE;
import static datadog.trace.instrumentation.ratpack.RatpackInstrumentation.EXEC_NAME;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
@@ -57,18 +57,7 @@ public final class RatpackHttpClientInstrumentation extends Instrumenter.Configu
return agentBuilder
.type(
not(isInterface()).and(hasSuperType(named("ratpack.http.client.HttpClient"))),
- classLoaderHasClasses(
- "ratpack.exec.Promise",
- "ratpack.exec.Result",
- "ratpack.func.Action",
- "ratpack.http.client.ReceivedResponse",
- "ratpack.http.client.RequestSpec",
- "ratpack.http.client.StreamedResponse",
- "ratpack.http.Request",
- "ratpack.func.Function",
- "ratpack.http.HttpMethod",
- "ratpack.http.MutableHeaders",
- "com.google.common.collect.ListMultimap"))
+ CLASSLOADER_CONTAINS_RATPACK_1_4_OR_ABOVE)
.transform(HTTP_CLIENT_HELPER_INJECTOR)
.transform(
DDAdvice.create()

MODIFY
dd-java-agent/instrumentation/ratpack-1.4/src/main/java/datadog/trace/instrumentation/ratpack/RatpackInstrumentation.java
dd-java-agent/instrumentation/ratpack-1.4/src/main/java/datadog/trace/instrumentation/ratpack/RatpackInstrumentation.java
package datadog.trace.instrumentation.ratpack;
-import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
+import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClassWithMethod;
import static net.bytebuddy.matcher.ElementMatchers.*;
import com.google.auto.service.AutoService;
@@ -17,6 +17,7 @@ import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.matcher.ElementMatcher;
import ratpack.exec.ExecStarter;
import ratpack.func.Action;
import ratpack.handling.HandlerDecorator;
@@ -38,10 +39,14 @@ public final class RatpackInstrumentation extends Instrumenter.Configurable {
"datadog.trace.instrumentation.ratpack.RatpackInstrumentation$ExecStarterAdvice",
"datadog.trace.instrumentation.ratpack.RatpackInstrumentation$ExecStarterAction");
- public static final TypeDescription.Latent ACTION_TYPE_DESCRIPTION =
+ static final TypeDescription.Latent ACTION_TYPE_DESCRIPTION =
new TypeDescription.Latent(
"ratpack.func.Action", Modifier.PUBLIC, null, Collections.emptyList());
+ static final ElementMatcher.Junction.AbstractBase<ClassLoader>
+ CLASSLOADER_CONTAINS_RATPACK_1_4_OR_ABOVE =
+ classLoaderHasClassWithMethod("ratpack.path.PathBinding", "getDescription");
+
public RatpackInstrumentation() {
super(EXEC_NAME);
}
@@ -57,14 +62,7 @@ public final class RatpackInstrumentation extends Instrumenter.Configurable {
return agentBuilder
.type(
named("ratpack.server.internal.ServerRegistry"),
- classLoaderHasClasses(
- "ratpack.handling.HandlerDecorator",
- "ratpack.registry.Registry",
- "ratpack.registry.RegistrySpec",
- "ratpack.handling.Context",
- "ratpack.handling.Handler",
- "ratpack.http.Request",
- "ratpack.http.Status"))
+ CLASSLOADER_CONTAINS_RATPACK_1_4_OR_ABOVE)
.transform(SERVER_REGISTRY_HELPER_INJECTOR)
.transform(
DDAdvice.create()
@@ -74,8 +72,7 @@ public final class RatpackInstrumentation extends Instrumenter.Configurable {
.asDecorator()
.type(
not(isInterface()).and(hasSuperType(named("ratpack.exec.ExecStarter"))),
- classLoaderHasClasses(
- "ratpack.exec.Execution", "ratpack.registry.RegistrySpec", "ratpack.func.Action"))
+ CLASSLOADER_CONTAINS_RATPACK_1_4_OR_ABOVE)
.transform(EXEC_STARTER_HELPER_INJECTOR)
.transform(
DDAdvice.create()
@@ -86,8 +83,7 @@ public final class RatpackInstrumentation extends Instrumenter.Configurable {
.type(
named("ratpack.exec.Execution")
.or(not(isInterface()).and(hasSuperType(named("ratpack.exec.Execution")))),
- classLoaderHasClasses(
- "ratpack.exec.ExecStarter", "ratpack.registry.RegistrySpec", "ratpack.func.Action"))
+ CLASSLOADER_CONTAINS_RATPACK_1_4_OR_ABOVE)
.transform(EXEC_STARTER_HELPER_INJECTOR)
.transform(
DDAdvice.create()

Correctly look for classes to determine minimum ratpack version