Catch and log instrumentation matcher exception
Catching instrumentation matcher exceptions at the Instrumenter level
allows other, unrelated instrumentation to match.
MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Instrumenter.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Instrumenter.java
@@ -80,7 +80,7 @@ public interface Instrumenter {
AgentBuilder.Identified.Extendable agentBuilder =
parentAgentBuilder
- .type(typeMatcher(), classLoaderMatcher())
+ .type(safeTypeMatcher(typeMatcher()), classLoaderMatcher())
.and(new MuzzleMatcher())
.transform(DDTransformers.defaultTransformers());
agentBuilder = injectHelperClasses(agentBuilder);
@@ -88,6 +88,23 @@ public interface Instrumenter {
return agentBuilder.asDecorator();
}
+ /** Wrap an ElementMatcher in a try-catch exception and log any exceptions. */
+ private ElementMatcher<? super TypeDescription> safeTypeMatcher(
+ final ElementMatcher<? super TypeDescription> instrumentationMatcher) {
+ return new ElementMatcher<TypeDescription>() {
+ @Override
+ public boolean matches(TypeDescription target) {
+ try {
+ return instrumentationMatcher.matches(target);
+ } catch (Exception e) {
+ log.debug(
+ "Instrumentation matcher unexpected exception: " + instrumentationPrimaryName, e);
+ return false;
+ }
+ }
+ };
+ }
+
private AgentBuilder.Identified.Extendable injectHelperClasses(
AgentBuilder.Identified.Extendable agentBuilder) {
final String[] helperClassNames = helperClassNames();

Catch and log instrumentation matcher exception

Catching instrumentation matcher exceptions at the Instrumenter level
allows other, unrelated instrumentation to match.