Constantify non decorator matcher

This commit is contained in:
Nikolay Martynov 2020-02-27 17:52:20 +01:00
parent bc85e69aad
commit 2f71ad850f
2 changed files with 11 additions and 7 deletions

View File

@ -23,9 +23,11 @@ import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.agent.builder.AgentBuilder; import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.annotation.AnnotationSource;
import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatcher.Junction;
import net.bytebuddy.utility.JavaModule; import net.bytebuddy.utility.JavaModule;
/** /**
@ -45,6 +47,12 @@ public interface Instrumenter {
@Slf4j @Slf4j
abstract class Default implements Instrumenter { abstract class Default implements Instrumenter {
// Added here instead of AgentInstaller's ignores because it's relatively
// expensive. https://github.com/DataDog/dd-trace-java/pull/1045
public static final Junction<AnnotationSource> NOT_DECORATOR_MATCHER =
not(isAnnotatedWith(named("javax.decorator.Decorator")));
private final SortedSet<String> instrumentationNames; private final SortedSet<String> instrumentationNames;
private final String instrumentationPrimaryName; private final String instrumentationPrimaryName;
private final InstrumentationContextProvider contextProvider; private final InstrumentationContextProvider contextProvider;
@ -83,9 +91,7 @@ public interface Instrumenter {
classLoaderMatcher(), classLoaderMatcher(),
"Instrumentation class loader matcher unexpected exception: " "Instrumentation class loader matcher unexpected exception: "
+ getClass().getName())) + getClass().getName()))
// Added here instead of AgentInstaller's ignores because it's relatively .and(NOT_DECORATOR_MATCHER)
// expensive. https://github.com/DataDog/dd-trace-java/pull/1045
.and(not(isAnnotatedWith(named("javax.decorator.Decorator"))))
.and(new MuzzleMatcher()) .and(new MuzzleMatcher())
.and(new PostMatchHook()) .and(new PostMatchHook())
.transform(DDTransformers.defaultTransformers()); .transform(DDTransformers.defaultTransformers());

View File

@ -2,13 +2,13 @@ package datadog.trace.agent.tooling.context;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.BOOTSTRAP_CLASSLOADER; import static datadog.trace.agent.tooling.ClassLoaderMatcher.BOOTSTRAP_CLASSLOADER;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.safeHasSuperType; import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.safeHasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith;
import static net.bytebuddy.matcher.ElementMatchers.isInterface; import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not; import static net.bytebuddy.matcher.ElementMatchers.not;
import datadog.trace.agent.tooling.HelperInjector; import datadog.trace.agent.tooling.HelperInjector;
import datadog.trace.agent.tooling.Instrumenter; import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.agent.tooling.Instrumenter.Default;
import datadog.trace.agent.tooling.Utils; import datadog.trace.agent.tooling.Utils;
import datadog.trace.api.Config; import datadog.trace.api.Config;
import datadog.trace.bootstrap.ContextStore; import datadog.trace.bootstrap.ContextStore;
@ -358,9 +358,7 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
not(isInterface()).and(safeHasSuperType(named(entry.getKey()))), not(isInterface()).and(safeHasSuperType(named(entry.getKey()))),
instrumenter.classLoaderMatcher()) instrumenter.classLoaderMatcher())
.and(safeToInjectFieldsMatcher()) .and(safeToInjectFieldsMatcher())
// Added here instead of AgentInstaller's ignores because it's relatively .and(Default.NOT_DECORATOR_MATCHER)
// expensive. https://github.com/DataDog/dd-trace-java/pull/1045
.and(not(isAnnotatedWith(named("javax.decorator.Decorator"))))
.transform(AgentBuilder.Transformer.NoOp.INSTANCE); .transform(AgentBuilder.Transformer.NoOp.INSTANCE);
/* /*