TraceConfigInstrumentation implements Instrumenter directly
This commit is contained in:
parent
77717d305b
commit
836f49205b
|
@ -105,11 +105,11 @@ public interface Instrumenter {
|
||||||
return getConfigEnabled("dd.integrations.enabled", true);
|
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)));
|
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(".", "_");
|
return name.toUpperCase().replace(".", "_");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,18 @@ import net.bytebuddy.description.method.MethodDescription;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.matcher.ElementMatcher;
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TraceConfig Instrumentation does not extend Default.
|
||||||
|
*
|
||||||
|
* <p>Instead it directly implements Instrumenter#instrument() and adds one default Instrumenter for
|
||||||
|
* every configured class+method-list.
|
||||||
|
*
|
||||||
|
* <p>If this becomes a more common use case the building logic should be abstracted out into a
|
||||||
|
* super class.
|
||||||
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@AutoService(Instrumenter.class)
|
@AutoService(Instrumenter.class)
|
||||||
public class TraceConfigInstrumentation extends Instrumenter.Default {
|
public class TraceConfigInstrumentation implements Instrumenter {
|
||||||
private static final String CONFIG_NAME = "dd.trace.methods";
|
private static final String CONFIG_NAME = "dd.trace.methods";
|
||||||
|
|
||||||
static final String PACKAGE_CLASS_NAME_REGEX = "[\\w.\\$]+";
|
static final String PACKAGE_CLASS_NAME_REGEX = "[\\w.\\$]+";
|
||||||
|
@ -38,9 +47,7 @@ public class TraceConfigInstrumentation extends Instrumenter.Default {
|
||||||
private final Map<String, Set<String>> classMethodsToTrace;
|
private final Map<String, Set<String>> classMethodsToTrace;
|
||||||
|
|
||||||
public TraceConfigInstrumentation() {
|
public TraceConfigInstrumentation() {
|
||||||
super("trace", "trace-config");
|
final String configString = Default.getPropOrEnv(CONFIG_NAME);
|
||||||
|
|
||||||
final String configString = getPropOrEnv(CONFIG_NAME);
|
|
||||||
if (configString == null || configString.trim().isEmpty()) {
|
if (configString == null || configString.trim().isEmpty()) {
|
||||||
classMethodsToTrace = Collections.emptyMap();
|
classMethodsToTrace = Collections.emptyMap();
|
||||||
|
|
||||||
|
@ -130,6 +137,16 @@ public class TraceConfigInstrumentation extends Instrumenter.Default {
|
||||||
throw new RuntimeException("TracerConfigInstrumentation must not use TypeMatcher");
|
throw new RuntimeException("TracerConfigInstrumentation must not use TypeMatcher");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ElementMatcher<? super ClassLoader> classLoaderMatcher() {
|
||||||
|
throw new RuntimeException("TracerConfigInstrumentation must not use classLoaderMatcher");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] helperClassNames() {
|
||||||
|
throw new RuntimeException("TracerConfigInstrumentation must not use helperClassNames");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<ElementMatcher, String> transformers() {
|
public Map<ElementMatcher, String> transformers() {
|
||||||
throw new RuntimeException("TracerConfigInstrumentation must not use transformers.");
|
throw new RuntimeException("TracerConfigInstrumentation must not use transformers.");
|
||||||
|
|
Loading…
Reference in New Issue