Merge pull request #1245 from DataDog/mar-kolya/single-ignores-matcher
Single ignores matcher
This commit is contained in:
commit
1f8acafc42
|
@ -1,13 +1,11 @@
|
|||
package datadog.trace.agent.tooling;
|
||||
|
||||
import static datadog.trace.agent.tooling.ClassLoaderMatcher.skipClassLoader;
|
||||
import static datadog.trace.agent.tooling.GlobalIgnoresMatcher.globalIgnoresMatcher;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.any;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.nameContains;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.nameMatches;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.none;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
import datadog.trace.api.Config;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
|
@ -64,75 +62,7 @@ public class AgentInstaller {
|
|||
// https://github.com/raphw/byte-buddy/issues/558
|
||||
// .with(AgentBuilder.LambdaInstrumentationStrategy.ENABLED)
|
||||
.ignore(any(), skipClassLoader())
|
||||
/**
|
||||
* Be very careful about the types of matchers used in this section as they are called
|
||||
* on every class load, so they must be fast. Generally speaking try to only use name
|
||||
* matchers as they don't have to load additional info.
|
||||
*/
|
||||
.or(
|
||||
nameStartsWith("datadog.trace.")
|
||||
// FIXME: We should remove this once
|
||||
// https://github.com/raphw/byte-buddy/issues/558 is fixed
|
||||
.and(
|
||||
not(
|
||||
named(
|
||||
"datadog.trace.bootstrap.instrumentation.java.concurrent.RunnableWrapper")
|
||||
.or(
|
||||
named(
|
||||
"datadog.trace.bootstrap.instrumentation.java.concurrent.CallableWrapper")))))
|
||||
.or(nameStartsWith("datadog.opentracing."))
|
||||
.or(nameStartsWith("datadog.slf4j."))
|
||||
.or(nameStartsWith("net.bytebuddy."))
|
||||
.or(
|
||||
nameStartsWith("java.")
|
||||
.and(
|
||||
not(
|
||||
named("java.net.URL")
|
||||
.or(named("java.net.HttpURLConnection"))
|
||||
.or(nameStartsWith("java.rmi."))
|
||||
.or(nameStartsWith("java.util.concurrent."))
|
||||
.or(
|
||||
nameStartsWith("java.util.logging.")
|
||||
// Concurrent instrumentation modifies the strucutre of
|
||||
// Cleaner class incompaibly with java9+ modules.
|
||||
// Working around until a long-term fix for modules can be
|
||||
// put in place.
|
||||
.and(not(named("java.util.logging.LogManager$Cleaner")))))))
|
||||
.or(
|
||||
nameStartsWith("com.sun.")
|
||||
.and(
|
||||
not(
|
||||
nameStartsWith("com.sun.messaging.")
|
||||
.or(nameStartsWith("com.sun.jersey.api.client")))))
|
||||
.or(
|
||||
nameStartsWith("sun.")
|
||||
.and(
|
||||
not(
|
||||
nameStartsWith("sun.net.www.protocol.")
|
||||
.or(nameStartsWith("sun.rmi.server"))
|
||||
.or(nameStartsWith("sun.rmi.transport"))
|
||||
.or(named("sun.net.www.http.HttpClient")))))
|
||||
.or(nameStartsWith("jdk."))
|
||||
.or(nameStartsWith("org.aspectj."))
|
||||
.or(nameStartsWith("org.groovy."))
|
||||
.or(nameStartsWith("org.codehaus.groovy.macro."))
|
||||
.or(nameStartsWith("com.intellij.rt.debugger."))
|
||||
.or(nameStartsWith("com.p6spy."))
|
||||
.or(nameStartsWith("com.newrelic."))
|
||||
.or(nameStartsWith("com.dynatrace."))
|
||||
.or(nameStartsWith("com.jloadtrace."))
|
||||
.or(nameStartsWith("com.appdynamics."))
|
||||
.or(nameStartsWith("com.singularity."))
|
||||
.or(nameStartsWith("com.jinspired."))
|
||||
.or(nameStartsWith("org.jinspired."))
|
||||
.or(nameStartsWith("org.apache.log4j.").and(not(named("org.apache.log4j.MDC"))))
|
||||
.or(nameStartsWith("org.slf4j.").and(not(named("org.slf4j.MDC"))))
|
||||
.or(nameContains("$JaxbAccessor"))
|
||||
.or(nameContains("CGLIB$$"))
|
||||
.or(nameContains("javassist"))
|
||||
.or(nameContains(".asm."))
|
||||
.or(nameContains("$__sisu"))
|
||||
.or(nameMatches("com\\.mchange\\.v2\\.c3p0\\..*Proxy"))
|
||||
.or(globalIgnoresMatcher())
|
||||
.or(matchesConfiguredExcludes());
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
|
|
|
@ -93,7 +93,7 @@ public class ByteBuddyElementMatchers {
|
|||
* @see net.bytebuddy.matcher.HasSuperTypeMatcher
|
||||
*/
|
||||
@HashCodeAndEqualsPlugin.Enhance
|
||||
public static class SafeHasSuperTypeMatcher<T extends TypeDescription>
|
||||
private static class SafeHasSuperTypeMatcher<T extends TypeDescription>
|
||||
extends ElementMatcher.Junction.AbstractBase<T> {
|
||||
|
||||
/** The matcher to apply to any super type of the matched type. */
|
||||
|
@ -192,7 +192,7 @@ public class ByteBuddyElementMatchers {
|
|||
* @see net.bytebuddy.matcher.ErasureMatcher
|
||||
*/
|
||||
@HashCodeAndEqualsPlugin.Enhance
|
||||
public static class SafeErasureMatcher<T extends TypeDefinition>
|
||||
private static class SafeErasureMatcher<T extends TypeDefinition>
|
||||
extends ElementMatcher.Junction.AbstractBase<T> {
|
||||
|
||||
/** The matcher to apply to the raw type of the matched element. */
|
||||
|
@ -234,7 +234,7 @@ public class ByteBuddyElementMatchers {
|
|||
* @see net.bytebuddy.matcher.FailSafeMatcher
|
||||
*/
|
||||
@HashCodeAndEqualsPlugin.Enhance
|
||||
public static class SafeMatcher<T> extends ElementMatcher.Junction.AbstractBase<T> {
|
||||
private static class SafeMatcher<T> extends ElementMatcher.Junction.AbstractBase<T> {
|
||||
|
||||
/** The delegate matcher that might throw an exception. */
|
||||
private final ElementMatcher<? super T> matcher;
|
||||
|
@ -296,7 +296,7 @@ public class ByteBuddyElementMatchers {
|
|||
|
||||
// TODO: add javadoc
|
||||
@HashCodeAndEqualsPlugin.Enhance
|
||||
public static class HasSuperMethodMatcher<T extends MethodDescription>
|
||||
private static class HasSuperMethodMatcher<T extends MethodDescription>
|
||||
extends ElementMatcher.Junction.AbstractBase<T> {
|
||||
|
||||
private final ElementMatcher<? super MethodDescription> matcher;
|
||||
|
@ -367,7 +367,7 @@ public class ByteBuddyElementMatchers {
|
|||
}
|
||||
}
|
||||
|
||||
public static class SafeExtendsClassMatcher<T extends TypeDescription>
|
||||
private static class SafeExtendsClassMatcher<T extends TypeDescription>
|
||||
extends ElementMatcher.Junction.AbstractBase<T> {
|
||||
|
||||
private final ElementMatcher<? super TypeDescription.Generic> matcher;
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
package datadog.trace.agent.tooling;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import net.bytebuddy.build.HashCodeAndEqualsPlugin;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@HashCodeAndEqualsPlugin.Enhance
|
||||
class GlobalIgnoresMatcher<T extends TypeDescription>
|
||||
extends ElementMatcher.Junction.AbstractBase<T> {
|
||||
|
||||
private static final Pattern COM_MCHANGE_PROXY =
|
||||
Pattern.compile("com\\.mchange\\.v2\\.c3p0\\..*Proxy");
|
||||
|
||||
public static <T extends TypeDescription> ElementMatcher.Junction<T> globalIgnoresMatcher() {
|
||||
return new GlobalIgnoresMatcher<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Be very careful about the types of matchers used in this section as they are called on every
|
||||
* class load, so they must be fast. Generally speaking try to only use name matchers as they
|
||||
* don't have to load additional info.
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(final T target) {
|
||||
final String name = target.getActualName();
|
||||
|
||||
if (name.startsWith("datadog.opentracing.")
|
||||
|| name.startsWith("datadog.slf4j.")
|
||||
|| name.startsWith("net.bytebuddy.")
|
||||
|| name.startsWith("jdk.")
|
||||
|| name.startsWith("org.aspectj.")
|
||||
|| name.startsWith("org.groovy.")
|
||||
|| name.startsWith("org.codehaus.groovy.macro.")
|
||||
|| name.startsWith("com.intellij.rt.debugger.")
|
||||
|| name.startsWith("com.p6spy.")
|
||||
|| name.startsWith("com.newrelic.")
|
||||
|| name.startsWith("com.dynatrace.")
|
||||
|| name.startsWith("com.jloadtrace.")
|
||||
|| name.startsWith("com.appdynamics.")
|
||||
|| name.startsWith("com.singularity.")
|
||||
|| name.startsWith("com.jinspired.")
|
||||
|| name.startsWith("org.jinspired.")
|
||||
|| name.startsWith("org.springframework.cglib.")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name.startsWith("datadog.trace.")) {
|
||||
// FIXME: We should remove this once
|
||||
// https://github.com/raphw/byte-buddy/issues/558 is fixed
|
||||
if (name.equals("datadog.trace.bootstrap.instrumentation.java.concurrent.RunnableWrapper")
|
||||
|| name.equals(
|
||||
"datadog.trace.bootstrap.instrumentation.java.concurrent.CallableWrapper")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name.startsWith("java.")) {
|
||||
if (name.equals("java.net.URL") || name.equals("java.net.HttpURLConnection")) {
|
||||
return false;
|
||||
}
|
||||
if (name.startsWith("java.rmi.") || name.startsWith("java.util.concurrent.")) {
|
||||
return false;
|
||||
}
|
||||
// Concurrent instrumentation modifies the structure of
|
||||
// Cleaner class incompatibly with java9+ modules.
|
||||
// Working around until a long-term fix for modules can be
|
||||
// put in place.
|
||||
if (name.startsWith("java.util.logging.")
|
||||
&& !name.equals("java.util.logging.LogManager$Cleaner")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name.startsWith("com.sun.")) {
|
||||
if (name.startsWith("com.sun.messaging.") || name.startsWith("com.sun.jersey.api.client")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name.startsWith("sun.")) {
|
||||
if (name.startsWith("sun.net.www.protocol.")
|
||||
|| name.startsWith("sun.rmi.server")
|
||||
|| name.startsWith("sun.rmi.transport")
|
||||
|| name.equals("sun.net.www.http.HttpClient")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name.startsWith("org.apache.log4j.")) {
|
||||
if (name.equals("org.apache.log4j.MDC")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name.startsWith("org.slf4j.")) {
|
||||
if (name.equals("org.slf4j.MDC")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name.contains("$JaxbAccessor")
|
||||
|| name.contains("CGLIB$$")
|
||||
|| name.contains("javassist")
|
||||
|| name.contains(".asm.")
|
||||
|| name.contains("$__sisu")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (COM_MCHANGE_PROXY.matcher(name).matches()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -44,7 +44,7 @@ public final class JaxRsAnnotationsInstrumentation extends Instrumenter.Default
|
|||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return safeHasSuperType(
|
||||
isAnnotatedWith(named("javax.ws.rs.Path"))
|
||||
.or(declaresMethod(isAnnotatedWith(named("javax.ws.rs.Path")))));
|
||||
.<TypeDescription>or(declaresMethod(isAnnotatedWith(named("javax.ws.rs.Path")))));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -43,7 +43,7 @@ public final class JaxRsAnnotationsInstrumentation extends Instrumenter.Default
|
|||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return safeHasSuperType(
|
||||
isAnnotatedWith(named("javax.ws.rs.Path"))
|
||||
.or(declaresMethod(isAnnotatedWith(named("javax.ws.rs.Path")))));
|
||||
.<TypeDescription>or(declaresMethod(isAnnotatedWith(named("javax.ws.rs.Path")))));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue