Fix TraceConfig tests
RENAME
dd-java-agent/instrumentation/trace-annotation/src/main/java/datadog/trace/instrumentation/trace_annotation/TraceAnnotationInstrumentation.java
dd-java-agent/instrumentation/trace-annotation/src/main/java/datadog/trace/instrumentation/trace_annotation/TraceAnnotationsInstrumentation.java
@@ -24,7 +24,7 @@ import net.bytebuddy.matcher.ElementMatcher;
@Slf4j
@AutoService(Instrumenter.class)
-public final class TraceAnnotationInstrumentation extends Instrumenter.Configurable {
+public final class TraceAnnotationsInstrumentation extends Instrumenter.Configurable {
private static final String CONFIG_NAME = "dd.trace.annotations";
static final String CONFIG_FORMAT =
@@ -45,7 +45,7 @@ public final class TraceAnnotationInstrumentation extends Instrumenter.Configura
private final Set<String> additionalTraceAnnotations;
- public TraceAnnotationInstrumentation() {
+ public TraceAnnotationsInstrumentation() {
super("trace", "trace-annotation");
final String configString = getPropOrEnv(CONFIG_NAME);

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
@@ -51,13 +51,16 @@ public class TraceConfigInstrumentation extends Instrumenter.Configurable {
} else {
final Map<String, Set<String>> toTrace = Maps.newHashMap();
- final String[] classMethods = configString.split(";");
+ final String[] classMethods = configString.split(";", -1);
for (final String classMethod : classMethods) {
- final String[] splitClassMethod = classMethod.split("\\[");
+ if (classMethod.trim().isEmpty()) {
+ continue;
+ }
+ final String[] splitClassMethod = classMethod.split("\\[", -1);
final String className = splitClassMethod[0];
final String method = splitClassMethod[1].trim();
final String methodNames = method.substring(0, method.length() - 1);
- final String[] splitMethodNames = methodNames.split(",");
+ final String[] splitMethodNames = methodNames.split(",", -1);
final Set<String> trimmedMethodNames =
Sets.newHashSetWithExpectedSize(splitMethodNames.length);
for (final String methodName : splitMethodNames) {

MODIFY
dd-java-agent/instrumentation/trace-annotation/src/test/groovy/ConfiguredTraceAnnotationsTest.groovy
dd-java-agent/instrumentation/trace-annotation/src/test/groovy/ConfiguredTraceAnnotationsTest.groovy
import datadog.trace.agent.test.AgentTestRunner
-import datadog.trace.instrumentation.trace_annotation.TraceAnnotationInstrumentation
+import datadog.trace.instrumentation.trace_annotation.TraceAnnotationsInstrumentation
import dd.test.trace.annotation.SayTracedHello
import spock.lang.Unroll
import java.util.concurrent.Callable
+import static TraceAnnotationsInstrumentation.DEFAULT_ANNOTATIONS
import static datadog.trace.agent.test.ListWriterAssert.assertTraces
import static datadog.trace.agent.test.TestUtils.withSystemProperty
-import static datadog.trace.instrumentation.trace_annotation.TraceAnnotationInstrumentation.DEFAULT_ANNOTATIONS
class ConfiguredTraceAnnotationsTest extends AgentTestRunner {
@@ -22,7 +22,7 @@ class ConfiguredTraceAnnotationsTest extends AgentTestRunner {
def "test disabled nr annotation"() {
setup:
- SayTracedHello.fromCallable()
+ SayTracedHello.fromCallableWhenDisabled()
expect:
TEST_WRITER == []
@@ -51,7 +51,7 @@ class ConfiguredTraceAnnotationsTest extends AgentTestRunner {
setup:
def config = null
withSystemProperty("dd.trace.annotations", value) {
- def instrumentation = new TraceAnnotationInstrumentation()
+ def instrumentation = new TraceAnnotationsInstrumentation()
config = instrumentation.additionalTraceAnnotations
}
expect:

MODIFY
dd-java-agent/instrumentation/trace-annotation/src/test/groovy/TraceConfigTest.groovy
dd-java-agent/instrumentation/trace-annotation/src/test/groovy/TraceConfigTest.groovy
@@ -60,6 +60,7 @@ class TraceConfigTest extends AgentTestRunner {
" " | [:]
"some.package.ClassName" | [:]
"some.package.ClassName[ , ]" | [:]
+ "some.package.ClassName[ , method]" | [:]
"some.package.Class\$Name[ method , ]" | ["some.package.Class\$Name": ["method"].toSet()]
"ClassName[ method1,]" | ["ClassName": ["method1"].toSet()]
"ClassName[method1 , method2]" | ["ClassName": ["method1", "method2"].toSet()]

MODIFY
dd-java-agent/instrumentation/trace-annotation/src/test/java/dd/test/trace/annotation/SayTracedHello.java
dd-java-agent/instrumentation/trace-annotation/src/test/java/dd/test/trace/annotation/SayTracedHello.java
@@ -44,4 +44,14 @@ public class SayTracedHello {
}
}.call();
}
+
+ public static String fromCallableWhenDisabled() throws Exception {
+ return new Callable<String>() {
+ @com.newrelic.api.agent.Trace
+ @Override
+ public String call() throws Exception {
+ return "Howdy!";
+ }
+ }.call();
+ }
}

Fix TraceConfig tests