Merge pull request #1267 from DataDog/mar-kolya/constantify-decorator-matcher

Constantify non decorator matcher
This commit is contained in:
Nikolay Martynov 2020-02-28 02:02:00 +01:00 committed by GitHub
commit 5c4cd95796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View File

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

View File

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

View File

@ -5,7 +5,6 @@ import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.sa
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;