Search in sources :

Example 16 with MethodMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.

the class PointCutConfigTest method nestedStaticMethodMatcher.

@Test
public void nestedStaticMethodMatcher() throws Exception {
    final String yaml = "oder:\n  class_matcher: java/lang/String\n  method_matcher: [ !static_method_matcher [ concat(Ljava/lang/String;)Ljava/lang/String; ], go()V ]";
    PointCutConfig config = new PointCutConfig(new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)));
    Assert.assertEquals(1, config.getPointCuts().size());
    Assert.assertNotNull(config.getPointCuts().get(0));
    MethodMatcher methodMatcher = config.getPointCuts().get(0).getMethodMatcher();
    Assert.assertTrue(methodMatcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "concat", "(Ljava/lang/String;)Ljava/lang/String;", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(methodMatcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "go", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(methodMatcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "dude", "(Ljava/lang/String;)Ljava/lang/String;", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) Test(org.junit.Test)

Example 17 with MethodMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.

the class InstrumentationConstructorTest method orMethodMatchers.

@Test
public void orMethodMatchers() throws Exception {
    String methods = "[ !exact_method_matcher [ 'getTracerFactoryClassName', '()Ljava/lang/String;' ], !exact_method_matcher [ 'getDude', '()V' ] ]";
    MethodMatcher[] matchers = new MethodMatcher[] { new ExactMethodMatcher("getTracerFactoryClassName", "()Ljava/lang/String;"), new ExactMethodMatcher("getDude", "()V") };
    MethodMatcher methodMatcher = load("!or_method_matcher " + methods);
    Assert.assertEquals(OrMethodMatcher.getMethodMatcher(matchers), methodMatcher);
}
Also used : ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) OrMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.OrMethodMatcher) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) Test(org.junit.Test)

Example 18 with MethodMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher 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)

Example 19 with MethodMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.

the class ExtensionServiceTest method testXMLExtensionOneFile.

/**
 * Tests reading in the xml extensions for one file.
 */
@Test
public void testXMLExtensionOneFile() throws Exception {
    setupFiles(true, XML_FILE_PATH_1);
    List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
    assertNotNull(pcs);
    assertEquals(3, pcs.size());
    List<String> classNames = new ArrayList<>();
    List<MethodMatcher> mms = new ArrayList<>();
    for (ExtensionClassAndMethodMatcher pc : pcs) {
        classNames.addAll(pc.getClassMatcher().getClassNames());
        mms.add(pc.getMethodMatcher());
    }
    // verify that classes
    assertEquals(3, classNames.size());
    assertTrue(classNames.contains("test/CustomExtensionTest$1"));
    assertTrue(classNames.contains("test/AbstractCustomExtensionTest"));
    assertTrue(classNames.contains("test/CustomExtensionTest"));
    // verify the methods
    assertEquals(3, mms.size());
    verifyMatch("run", "()V", mms);
    verifyMatch("abstractTest1", "()V", mms);
    verifyMatch("abstractTest2", "()V", mms);
    verifyMatch("test2", "(Ljava/lang/String;J)V", mms);
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ArrayList(java.util.ArrayList) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) Test(org.junit.Test)

Example 20 with MethodMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.

the class PointCutConfigTest method invalidMethodDescriptor.

@Test
public void invalidMethodDescriptor() throws Exception {
    PointCutConfig config = new PointCutConfig(new ByteArrayInputStream("pre:\n  class_matcher: !exact_class_matcher 'java/lang/String'\n  method_matcher: !exact_method_matcher [ 'concat', '(java/lang/String;)Ljava/lang/String;' ]\n".getBytes(StandardCharsets.UTF_8)));
    List<ExtensionClassAndMethodMatcher> pcs = config.getPointCuts();
    Assert.assertEquals(1, pcs.size());
    ExtensionClassAndMethodMatcher pc = config.getPointCuts().get(0);
    Assert.assertNotNull(pc);
    MethodMatcher methodMatcher = pc.getMethodMatcher();
    Assert.assertTrue(methodMatcher instanceof NoMethodsMatcher);
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) NoMethodsMatcher(com.newrelic.agent.instrumentation.methodmatchers.NoMethodsMatcher) ByteArrayInputStream(java.io.ByteArrayInputStream) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) Test(org.junit.Test)

Aggregations

MethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)21 ExtensionClassAndMethodMatcher (com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher)19 Test (org.junit.Test)16 ExactMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher)11 ArrayList (java.util.ArrayList)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ClassMatcher)3 ExactClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher)3 AnnotationMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher)3 OrMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.OrMethodMatcher)3 LambdaMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.LambdaMethodMatcher)2 ReturnTypeMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ReturnTypeMethodMatcher)2 ParameterAttributeName (com.newrelic.agent.instrumentation.tracing.ParameterAttributeName)2 List (java.util.List)2 BaseConfig (com.newrelic.agent.config.BaseConfig)1 Config (com.newrelic.agent.config.Config)1 Extension (com.newrelic.agent.extension.beans.Extension)1 Pointcut (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut)1 Method (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method)1 AllClassesMatcher (com.newrelic.agent.instrumentation.classmatchers.AllClassesMatcher)1