From 836f49205b7c4435d9d22226ff49e8222e6e4000 Mon Sep 17 00:00:00 2001 From: Andrew Kent Date: Sat, 7 Jul 2018 14:01:08 -0400 Subject: [PATCH] TraceConfigInstrumentation implements Instrumenter directly --- .../trace/agent/tooling/Instrumenter.java | 4 +-- .../TraceConfigInstrumentation.java | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Instrumenter.java b/dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Instrumenter.java index 6003586367..48539b81e5 100644 --- a/dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Instrumenter.java +++ b/dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Instrumenter.java @@ -105,11 +105,11 @@ public interface Instrumenter { return getConfigEnabled("dd.integrations.enabled", true); } - protected static String getPropOrEnv(final String name) { + public static String getPropOrEnv(final String name) { return System.getProperty(name, System.getenv(propToEnvName(name))); } - private static String propToEnvName(final String name) { + public static String propToEnvName(final String name) { return name.toUpperCase().replace(".", "_"); } } diff --git a/dd-java-agent/instrumentation/trace-annotation/src/main/java/datadog/trace/instrumentation/trace_annotation/TraceConfigInstrumentation.java b/dd-java-agent/instrumentation/trace-annotation/src/main/java/datadog/trace/instrumentation/trace_annotation/TraceConfigInstrumentation.java index 502eef6bdd..b0b8e9e991 100644 --- a/dd-java-agent/instrumentation/trace-annotation/src/main/java/datadog/trace/instrumentation/trace_annotation/TraceConfigInstrumentation.java +++ b/dd-java-agent/instrumentation/trace-annotation/src/main/java/datadog/trace/instrumentation/trace_annotation/TraceConfigInstrumentation.java @@ -17,9 +17,18 @@ import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; +/** + * TraceConfig Instrumentation does not extend Default. + * + *

Instead it directly implements Instrumenter#instrument() and adds one default Instrumenter for + * every configured class+method-list. + * + *

If this becomes a more common use case the building logic should be abstracted out into a + * super class. + */ @Slf4j @AutoService(Instrumenter.class) -public class TraceConfigInstrumentation extends Instrumenter.Default { +public class TraceConfigInstrumentation implements Instrumenter { private static final String CONFIG_NAME = "dd.trace.methods"; static final String PACKAGE_CLASS_NAME_REGEX = "[\\w.\\$]+"; @@ -38,9 +47,7 @@ public class TraceConfigInstrumentation extends Instrumenter.Default { private final Map> classMethodsToTrace; public TraceConfigInstrumentation() { - super("trace", "trace-config"); - - final String configString = getPropOrEnv(CONFIG_NAME); + final String configString = Default.getPropOrEnv(CONFIG_NAME); if (configString == null || configString.trim().isEmpty()) { classMethodsToTrace = Collections.emptyMap(); @@ -130,6 +137,16 @@ public class TraceConfigInstrumentation extends Instrumenter.Default { throw new RuntimeException("TracerConfigInstrumentation must not use TypeMatcher"); } + @Override + public ElementMatcher classLoaderMatcher() { + throw new RuntimeException("TracerConfigInstrumentation must not use classLoaderMatcher"); + } + + @Override + public String[] helperClassNames() { + throw new RuntimeException("TracerConfigInstrumentation must not use helperClassNames"); + } + @Override public Map transformers() { throw new RuntimeException("TracerConfigInstrumentation must not use transformers.");