Search in sources :

Example 1 with ClassMatcher

use of com.newrelic.agent.instrumentation.classmatchers.ClassMatcher in project newrelic-java-agent by newrelic.

the class ExtensionConversionUtility method createPointCut.

/**
 * Converts the xml point cut into a java agent point cut.
 *
 * @return The point cut object with the matchers set.
 */
private static ExtensionClassAndMethodMatcher createPointCut(Extension extension, final Pointcut cut, final String metricPrefix, final String pName, final Map<String, MethodMapper> classesToMethods, boolean custom, InstrumentationType type, boolean isAttsEnabled) throws XmlException {
    ClassMatcher classMatcher;
    if (cut.getMethodAnnotation() != null) {
        classMatcher = new AllClassesMatcher();
    } else {
        classMatcher = createClassMatcher(cut, pName);
    }
    MethodMatcher methodMatcher = createMethodMatcher(cut, pName, classesToMethods);
    List<ParameterAttributeName> reportedParams = null;
    if (!isAttsEnabled) {
        // looks like this could be modified later
        reportedParams = new ArrayList<>();
    } else {
        reportedParams = getParameterAttributeNames(cut.getMethod());
    }
    return new ExtensionClassAndMethodMatcher(extension, cut, metricPrefix, classMatcher, methodMatcher, custom, reportedParams, type);
}
Also used : ParameterAttributeName(com.newrelic.agent.instrumentation.tracing.ParameterAttributeName) ClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ClassMatcher) ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) ChildClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ChildClassMatcher) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) AllClassesMatcher(com.newrelic.agent.instrumentation.classmatchers.AllClassesMatcher) AnnotationMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher) LambdaMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.LambdaMethodMatcher) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ReturnTypeMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ReturnTypeMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)

Example 2 with ClassMatcher

use of com.newrelic.agent.instrumentation.classmatchers.ClassMatcher in project newrelic-java-agent by newrelic.

the class ClassNameFilter method addClassMatcherIncludes.

public void addClassMatcherIncludes(Collection<ClassMatcher> classMatchers) {
    Set<String> classNames = new HashSet<>();
    classNames.addAll(includeClasses);
    for (ClassMatcher classMatcher : classMatchers) {
        for (String className : classMatcher.getClassNames()) {
            classNames.add(className);
        }
    }
    logger.finer("Class name inclusions: " + classNames);
    includeClasses = classNames;
}
Also used : ClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ClassMatcher) HashSet(java.util.HashSet)

Example 3 with ClassMatcher

use of com.newrelic.agent.instrumentation.classmatchers.ClassMatcher in project newrelic-java-agent by newrelic.

the class InstrumentationConstructorTest method andOrClassMatchers.

@Test
public void andOrClassMatchers() throws Exception {
    String classes = "[ !exact_class_matcher 'java/lang/Dude', !exact_class_matcher 'java/lang/Object' ]";
    ClassMatcher[] matchers = new ClassMatcher[] { new ExactClassMatcher("java/lang/Dude"), new ExactClassMatcher("java/lang/Object") };
    AndClassMatcher classMatcher = load("!and_class_matcher " + classes);
    Assert.assertEquals(new AndClassMatcher(matchers), classMatcher);
    ClassMatcher orClassMatcher = load("!or_class_matcher " + classes);
    Assert.assertEquals(OrClassMatcher.getClassMatcher(matchers), orClassMatcher);
}
Also used : ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) ClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ClassMatcher) AndClassMatcher(com.newrelic.agent.instrumentation.classmatchers.AndClassMatcher) OrClassMatcher(com.newrelic.agent.instrumentation.classmatchers.OrClassMatcher) ChildClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ChildClassMatcher) ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) AndClassMatcher(com.newrelic.agent.instrumentation.classmatchers.AndClassMatcher) Test(org.junit.Test)

Example 4 with ClassMatcher

use of com.newrelic.agent.instrumentation.classmatchers.ClassMatcher in project newrelic-java-agent by newrelic.

the class ExtensionConversionUtilityTest method createClassMatcher.

@Test
public void createClassMatcher() throws XmlException {
    Pointcut pointcut = new Pointcut();
    ClassName name = new ClassName();
    name.setValue(ArrayList.class.getName());
    pointcut.setClassName(name);
    ClassMatcher classMatcher = ExtensionConversionUtility.createClassMatcher(pointcut, "test");
    Assert.assertTrue(classMatcher instanceof ExactClassMatcher);
    Assert.assertTrue(classMatcher.isMatch(ArrayList.class));
}
Also used : Pointcut(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut) ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) ClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ClassMatcher) ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) ClassName(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.ClassName) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with ClassMatcher

use of com.newrelic.agent.instrumentation.classmatchers.ClassMatcher in project newrelic-java-agent by newrelic.

the class YmlExtensionPointCutConverter method createExtensionPointCut.

public static ExtensionClassAndMethodMatcher createExtensionPointCut(Map attrs, String defaultMetricPrefix, ClassLoader classLoader, String extName) {
    ClassMatcher classMatcher = getClassMatcher(attrs);
    MethodMatcher methodMatcher = getMethodMatcher(attrs);
    boolean dispatcher = getDispatcher(attrs);
    Config newConfig = new BaseConfig(attrs);
    boolean skipTransTrace = newConfig.getProperty(SKIP_TRANS_KEY, Boolean.FALSE);
    boolean ignoreTrans = newConfig.getProperty(IGNORE_TRANS_KEY, Boolean.FALSE);
    String metricPrefix = defaultMetricPrefix;
    String metricName;
    Object format = attrs.get(METRIC_NAME_FORMAT_KEY);
    if (format instanceof String) {
        metricName = format.toString();
    } else if (null == format) {
        metricName = null;
    } else if (format instanceof MetricNameFormatFactory) {
        // sorry - not supported anymore
        Agent.LOG.log(Level.WARNING, MessageFormat.format("The object property {0} is no longer supported in the agent. The default naming mechanism will be used.", METRIC_NAME_FORMAT_KEY));
        metricName = null;
    } else {
        throw new RuntimeException(MessageFormat.format("Unsupported {0} value", METRIC_NAME_FORMAT_KEY));
    }
    String tracerFactoryNameString = getTracerFactoryName(attrs, defaultMetricPrefix, dispatcher, format, classLoader);
    String nameOfExtension = (extName == null) ? "Unknown" : extName;
    return new ExtensionClassAndMethodMatcher(nameOfExtension, metricName, metricPrefix, classMatcher, methodMatcher, dispatcher, skipTransTrace, false, ignoreTrans, tracerFactoryNameString);
}
Also used : ClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ClassMatcher) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) BaseConfig(com.newrelic.agent.config.BaseConfig) Config(com.newrelic.agent.config.Config) BaseConfig(com.newrelic.agent.config.BaseConfig) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)

Aggregations

ClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ClassMatcher)6 ExactClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher)4 ExtensionClassAndMethodMatcher (com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher)3 MethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)3 Test (org.junit.Test)3 ChildClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ChildClassMatcher)2 BaseConfig (com.newrelic.agent.config.BaseConfig)1 Config (com.newrelic.agent.config.Config)1 Pointcut (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut)1 ClassName (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.ClassName)1 AllClassesMatcher (com.newrelic.agent.instrumentation.classmatchers.AllClassesMatcher)1 AndClassMatcher (com.newrelic.agent.instrumentation.classmatchers.AndClassMatcher)1 OrClassMatcher (com.newrelic.agent.instrumentation.classmatchers.OrClassMatcher)1 AnnotationMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher)1 ExactMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher)1 LambdaMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.LambdaMethodMatcher)1 ReturnTypeMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ReturnTypeMethodMatcher)1 ParameterAttributeName (com.newrelic.agent.instrumentation.tracing.ParameterAttributeName)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1