Search in sources :

Example 1 with MethodMatcher

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

the class ExtensionConversionUtility method getParameterAttributeNames.

private static List<ParameterAttributeName> getParameterAttributeNames(List<Method> methods) {
    List<ParameterAttributeName> reportedParams = new ArrayList<>();
    for (Method m : methods) {
        if (m.getParameters() != null && m.getParameters().getType() != null) {
            for (int i = 0; i < m.getParameters().getType().size(); i++) {
                com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method.Parameters.Type t = m.getParameters().getType().get(i);
                if (t.getAttributeName() != null) {
                    try {
                        MethodMatcher methodMatcher = MethodMatcherUtility.createMethodMatcher("DummyClassName", m, new HashMap<String, MethodMapper>(), "");
                        ParameterAttributeName reportedParam = new ParameterAttributeName(i, t.getAttributeName(), methodMatcher);
                        reportedParams.add(reportedParam);
                    } catch (Exception e) {
                        Agent.LOG.log(Level.FINEST, e, e.getMessage());
                    }
                }
            }
        }
    }
    return reportedParams;
}
Also used : ArrayList(java.util.ArrayList) Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) Pointcut(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut) Extension(com.newrelic.agent.extension.beans.Extension) ParameterAttributeName(com.newrelic.agent.instrumentation.tracing.ParameterAttributeName) 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 MethodMatcher

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

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

the class PointCutFactory method getMethodMatcher.

static MethodMatcher getMethodMatcher(Object yaml) {
    MethodMatcher matcher = null;
    if (yaml instanceof MethodMatcher) {
        matcher = (MethodMatcher) yaml;
    } else if (yaml instanceof List) {
        List list = (List) yaml;
        if (!list.isEmpty() && list.get(0) instanceof String && list.get(0).toString().indexOf('(') < 0) {
            return createExactMethodMatcher(list.get(0).toString().trim(), Strings.trim(list.subList(1, list.size())));
        }
        return OrMethodMatcher.getMethodMatcher(getMethodMatchers(list));
    } else if (yaml instanceof String) {
        String text = yaml.toString().trim();
        int index = text.indexOf('(');
        if (index > 0) {
            String methodName = text.substring(0, index);
            String methodDesc = text.substring(index);
            return createExactMethodMatcher(methodName, methodDesc);
        } else {
            return new ExactMethodMatcher(text);
        }
    }
    return matcher;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) OrMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.OrMethodMatcher) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher)

Example 4 with MethodMatcher

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

the class ExtensionServiceTest method testXMLExtensionWithDuplicates.

@Test
public void testXMLExtensionWithDuplicates() throws Exception {
    setupFiles(true, XML_DUPS);
    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 classes
    assertEquals(3, classNames.size());
    assertTrue(classNames.contains("test/TheClass"));
    assertTrue(classNames.contains("test/TheOtherClass"));
    // verify the methods
    assertEquals(3, mms.size());
    verifyMatch("run", "()Ljava/lang/String;", mms);
    verifyMatch("merge", "()Ljava/lang/String;", mms);
    verifyMatch("migrate", "()Ljava/lang/String;", mms);
    verifyMatch("run", "()Ljava/lang/String;", mms);
    verifyMatch("merge", "()Ljava/lang/String;", mms);
    verifyMatch("run", "(Ljava/lang/String;J)Ljava/lang/String;", 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 5 with MethodMatcher

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

the class ExtensionServiceTest method testYMLExtensionIneFile.

@Test
public void testYMLExtensionIneFile() throws Exception {
    setupFiles(true, YML_FILE_PATH_1_1);
    List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
    assertNotNull(pcs);
    assertEquals(1, pcs.size());
    List<String> classNames = new ArrayList<>();
    List<MethodMatcher> mms = new ArrayList<>();
    for (ExtensionClassAndMethodMatcher pc : pcs) {
        classNames.addAll(pc.getClassMatcher().getClassNames());
        assertEquals(ExactClassMatcher.class, pc.getClassMatcher().getClass());
        mms.add(pc.getMethodMatcher());
    }
    // verify that classes
    assertEquals(1, classNames.size());
    assertTrue(classNames.contains("java/lang/instrument/Instrumentation/Agent"));
    // verify method matcher
    assertEquals(1, mms.size());
    assertTrue(mms.get(0).matches(MethodMatcher.UNSPECIFIED_ACCESS, "getVersion", "()Ljava/lang/String;", com.google.common.collect.ImmutableSet.<String>of()));
}
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)

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