Add list of blacklisted spring classes
This commit is contained in:
parent
39e577ad97
commit
fa3f449ec4
|
@ -1,12 +1,12 @@
|
|||
package datadog.trace.agent.tooling;
|
||||
|
||||
import static datadog.trace.agent.tooling.ClassLoaderMatcher.skipClassLoader;
|
||||
import static datadog.trace.agent.tooling.bytebuddy.GlobalIgnoresMatcher.globalIgnoresMatcher;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.any;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.none;
|
||||
|
||||
import datadog.trace.agent.tooling.bytebuddy.GlobalIgnoresMatcher;
|
||||
import datadog.trace.api.Config;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.util.ArrayList;
|
||||
|
@ -53,6 +53,8 @@ public class AgentInstaller {
|
|||
|
||||
addByteBuddyRawSetting();
|
||||
|
||||
final GlobalIgnoresMatcher<TypeDescription> globalIgnoresMatcher = new GlobalIgnoresMatcher<>();
|
||||
|
||||
AgentBuilder agentBuilder =
|
||||
new AgentBuilder.Default()
|
||||
.disableClassFormatChanges()
|
||||
|
@ -65,7 +67,7 @@ public class AgentInstaller {
|
|||
// https://github.com/raphw/byte-buddy/issues/558
|
||||
// .with(AgentBuilder.LambdaInstrumentationStrategy.ENABLED)
|
||||
.ignore(any(), skipClassLoader())
|
||||
.or(globalIgnoresMatcher())
|
||||
.or(globalIgnoresMatcher)
|
||||
.or(matchesConfiguredExcludes());
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
|
@ -86,6 +88,8 @@ public class AgentInstaller {
|
|||
|
||||
try {
|
||||
agentBuilder = instrumenter.instrument(agentBuilder);
|
||||
globalIgnoresMatcher.addBlacklistedPrefixes(instrumenter.getLibraryBlacklistedPrefixes());
|
||||
|
||||
numInstrumenters++;
|
||||
} catch (final Exception | LinkageError e) {
|
||||
log.error("Unable to load instrumentation {}", instrumenter.getClass().getName(), e);
|
||||
|
|
|
@ -16,6 +16,7 @@ import datadog.trace.agent.tooling.muzzle.ReferenceMatcher;
|
|||
import datadog.trace.api.Config;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -43,6 +44,13 @@ public interface Instrumenter {
|
|||
*/
|
||||
AgentBuilder instrument(AgentBuilder agentBuilder);
|
||||
|
||||
/**
|
||||
* Returns a collection of type name prefixes that should be blacklisted for all instrumentations
|
||||
*
|
||||
* <p>//TODO convert to a default method when the agent is Java 8+
|
||||
*/
|
||||
Collection<String> getLibraryBlacklistedPrefixes();
|
||||
|
||||
@Slf4j
|
||||
abstract class Default implements Instrumenter {
|
||||
private final SortedSet<String> instrumentationNames;
|
||||
|
@ -96,6 +104,11 @@ public interface Instrumenter {
|
|||
return agentBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getLibraryBlacklistedPrefixes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
private AgentBuilder.Identified.Extendable injectHelperClasses(
|
||||
AgentBuilder.Identified.Extendable agentBuilder) {
|
||||
final String[] helperClassNames = helperClassNames();
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package datadog.trace.agent.tooling.bytebuddy;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import net.bytebuddy.build.HashCodeAndEqualsPlugin;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -9,11 +12,13 @@ import net.bytebuddy.matcher.ElementMatcher;
|
|||
public class GlobalIgnoresMatcher<T extends TypeDescription>
|
||||
extends ElementMatcher.Junction.AbstractBase<T> {
|
||||
|
||||
private final Set<String> blacklistedPrefixes = new HashSet<>();
|
||||
|
||||
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<>();
|
||||
public void addBlacklistedPrefixes(final Collection<String> prefixes) {
|
||||
blacklistedPrefixes.addAll(prefixes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,8 +45,7 @@ public class GlobalIgnoresMatcher<T extends TypeDescription>
|
|||
|| name.startsWith("com.appdynamics.")
|
||||
|| name.startsWith("com.singularity.")
|
||||
|| name.startsWith("com.jinspired.")
|
||||
|| name.startsWith("org.jinspired.")
|
||||
|| name.startsWith("org.springframework.cglib.")) {
|
||||
|| name.startsWith("org.jinspired.")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -122,6 +126,12 @@ public class GlobalIgnoresMatcher<T extends TypeDescription>
|
|||
return true;
|
||||
}
|
||||
|
||||
for (final String prefix : blacklistedPrefixes) {
|
||||
if (name.startsWith(prefix)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.test.base.HttpServerTestAdvice;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
|
@ -24,4 +26,9 @@ public class JettyTestInstrumentation implements Instrumenter {
|
|||
new AgentBuilder.Transformer.ForAdvice()
|
||||
.advice(named("handle"), HttpServerTestAdvice.ServerEntryAdvice.class.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getLibraryBlacklistedPrefixes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.test.base.HttpServerTestAdvice;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
|
@ -17,4 +19,9 @@ public class GrizzlyTestInstrumentation implements Instrumenter {
|
|||
.advice(
|
||||
named("handleRead"), HttpServerTestAdvice.ServerEntryAdvice.class.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getLibraryBlacklistedPrefixes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.test.base.HttpServerTestAdvice;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
|
@ -16,4 +18,9 @@ public class GrizzlyTestInstrumentation implements Instrumenter {
|
|||
new AgentBuilder.Transformer.ForAdvice()
|
||||
.advice(named("doHandle"), HttpServerTestAdvice.ServerEntryAdvice.class.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getLibraryBlacklistedPrefixes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ import com.google.common.collect.ImmutableMap;
|
|||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
|
||||
import datadog.trace.context.TraceScope;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
|
@ -52,6 +54,11 @@ public final class AsyncPropagatingDisableInstrumentation implements Instrumente
|
|||
return agentBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getLibraryBlacklistedPrefixes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
// Not Using AutoService to hook up this instrumentation
|
||||
public static class DisableAsyncInstrumentation extends Default {
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
|
@ -9,4 +11,9 @@ public class NoOpInstrumentation implements Instrumenter {
|
|||
public AgentBuilder instrument(final AgentBuilder agentBuilder) {
|
||||
return agentBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getLibraryBlacklistedPrefixes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.test.base.HttpServerTestAdvice;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
|
@ -17,4 +19,9 @@ public class NettyServerTestInstrumentation implements Instrumenter {
|
|||
.advice(
|
||||
named("channelRead"), HttpServerTestAdvice.ServerEntryAdvice.class.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getLibraryBlacklistedPrefixes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.test.base.HttpServerTestAdvice;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
|
@ -25,4 +27,9 @@ public class ServletTestInstrumentation implements Instrumenter {
|
|||
named("headerComplete"),
|
||||
HttpServerTestAdvice.ServerEntryAdvice.class.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getLibraryBlacklistedPrefixes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import com.google.auto.service.AutoService;
|
|||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
|
||||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -47,6 +49,46 @@ public final class DispatcherServletInstrumentation extends Instrumenter.Default
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getLibraryBlacklistedPrefixes() {
|
||||
return Arrays.asList(
|
||||
"org.springframework.cglib.",
|
||||
"org.springframework.aop.",
|
||||
"org.springframework.beans.factory.annotation.",
|
||||
"org.springframework.beans.factory.config.",
|
||||
"org.springframework.beans.factory.parsing.",
|
||||
"org.springframework.beans.factory.xml.",
|
||||
"org.springframework.beans.propertyeditors.",
|
||||
"org.springframework.boot.autoconfigure.cache.",
|
||||
"org.springframework.boot.autoconfigure.condition.",
|
||||
"org.springframework.boot.autoconfigure.http.",
|
||||
"org.springframework.boot.autoconfigure.jackson.",
|
||||
"org.springframework.boot.autoconfigure.web.",
|
||||
"org.springframework.boot.context.",
|
||||
"org.springframework.boot.convert.",
|
||||
"org.springframework.boot.diagnostics.",
|
||||
"org.springframework.boot.web.server.",
|
||||
"org.springframework.boot.web.servlet.",
|
||||
"org.springframework.context.annotation.",
|
||||
"org.springframework.context.event.",
|
||||
"org.springframework.context.expression.",
|
||||
"org.springframework.core.annotation.",
|
||||
"org.springframework.core.convert.",
|
||||
"org.springframework.core.env.",
|
||||
"org.springframework.core.io.",
|
||||
"org.springframework.core.type.",
|
||||
"org.springframework.expression",
|
||||
"org.springframework.format",
|
||||
"org.springframework.http",
|
||||
"org.springframework.ui",
|
||||
"org.springframework.validation",
|
||||
"org.springframework.web.context",
|
||||
"org.springframework.web.filter",
|
||||
"org.springframework.web.method",
|
||||
"org.springframework.web.multipart",
|
||||
"org.springframework.web.util");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
|
||||
|
|
|
@ -5,6 +5,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.test.base.HttpServerTestAdvice;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
|
@ -19,4 +21,9 @@ public class ServletTestInstrumentation implements Instrumenter {
|
|||
new AgentBuilder.Transformer.ForAdvice()
|
||||
.advice(named("service"), HttpServerTestAdvice.ServerEntryAdvice.class.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getLibraryBlacklistedPrefixes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.google.common.collect.Maps;
|
|||
import com.google.common.collect.Sets;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.api.Config;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -108,6 +109,11 @@ public class TraceConfigInstrumentation implements Instrumenter {
|
|||
return agentBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getLibraryBlacklistedPrefixes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
// Not Using AutoService to hook up this instrumentation
|
||||
public static class TracerClassInstrumentation extends Default {
|
||||
private final String className;
|
||||
|
|
|
@ -5,6 +5,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.test.base.HttpServerTestAdvice;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
|
@ -19,4 +21,9 @@ public class NettyServerTestInstrumentation implements Instrumenter {
|
|||
.advice(
|
||||
named("channelRead"), HttpServerTestAdvice.ServerEntryAdvice.class.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getLibraryBlacklistedPrefixes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue