Catch and log instrumentation matcher exception

Catching instrumentation matcher exceptions at the Instrumenter level
allows other, unrelated instrumentation to match.
This commit is contained in:
Andrew Kent 2018-08-14 12:43:23 -07:00
parent d64b162539
commit 57e85d4a13
1 changed files with 18 additions and 1 deletions

View File

@ -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();