Add test. Address other PR concerns

This commit is contained in:
Laplie Anderson 2019-08-29 17:48:29 -04:00
parent 08de0b02fd
commit ae9f8e15dd
5 changed files with 91 additions and 2 deletions

View File

@ -80,7 +80,8 @@ public class AgentInstaller {
"datadog.trace.bootstrap.instrumentation.java.concurrent.RunnableWrapper")
.or(
named(
"datadog.trace.bootstrap.instrumentation.java.concurrent.CallableWrapper")))))
"datadog.trace.bootstrap.instrumentation.java.concurrent.CallableWrapper")
.or(nameStartsWith("datadog.trace.agent.test"))))))
.or(nameStartsWith("datadog.opentracing."))
.or(nameStartsWith("datadog.slf4j."))
.or(nameStartsWith("net.bytebuddy."))
@ -142,7 +143,7 @@ public class AgentInstaller {
try {
agentBuilder = instrumenter.instrument(agentBuilder);
numInstrumenters++;
} catch (final Throwable e) {
} catch (final Exception | LinkageError e) {
log.error("Unable to load instrumentation {}", instrumenter.getClass().getName(), e);
}
}

View File

@ -0,0 +1,18 @@
package datadog.trace.agent.tooling
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.agent.test.TestClass
class AgentInstallerTest extends AgentTestRunner {
def "Exception in instrumentation is limited to that instrumentation"() {
given:
TestClass instance = new TestClass()
when:
String returnValue = instance.doSomething()
then:
returnValue == "overridden value"
}
}

View File

@ -0,0 +1,26 @@
package datadog.trace.agent.test;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import java.util.Collections;
import java.util.Map;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
@AutoService(Instrumenter.class)
public class BadInstrumentation extends Instrumenter.Default {
public BadInstrumentation() {
super("bad-test-instrumentation");
}
@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
throw new RuntimeException("Test Exception");
}
@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return Collections.emptyMap();
}
}

View File

@ -0,0 +1,37 @@
package datadog.trace.agent.test;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.named;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
@AutoService(Instrumenter.class)
public class GoodInstrumentation extends Instrumenter.Default {
public GoodInstrumentation() {
super("good-test-instrumentation");
}
@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
return named(TestClass.class.getName());
}
@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return singletonMap(named("doSomething"), GoodInstrumentationAdvice.class.getName());
}
public static class GoodInstrumentationAdvice {
@Advice.OnMethodExit
public static void changeReturn(@Advice.Return(readOnly = false) String originalValue) {
originalValue = "overridden value";
}
}
}

View File

@ -0,0 +1,7 @@
package datadog.trace.agent.test;
public class TestClass {
public String doSomething() {
return "original value";
}
}