Search in sources :

Example 1 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher 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 ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class InstrumentTestUtils method createTransformerAndRetransformSuperclass.

public static void createTransformerAndRetransformSuperclass(String superclassName, String methodName, String methodDesc) throws UnmodifiableClassException {
    ExtensionClassAndMethodMatcher pc = InstrumentTestUtils.createSuperclassPointCut(superclassName, methodName, methodDesc);
    List<ExtensionClassAndMethodMatcher> list = new LinkedList<>();
    list.add(pc);
    ServiceFactory.getClassTransformerService().getLocalRetransformer().appendClassMethodMatchers(list);
    InstrumentTestUtils.retransformAllMatching(pc);
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) LinkedList(java.util.LinkedList)

Example 3 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class InstrumentTestUtils method createTransformerAndRetransformClass.

public static void createTransformerAndRetransformClass(String className, String methodName, String methodDesc) throws UnmodifiableClassException {
    ExtensionClassAndMethodMatcher pc = InstrumentTestUtils.createPointCut(className, methodName, methodDesc);
    List<ExtensionClassAndMethodMatcher> list = new LinkedList<>();
    list.add(pc);
    ServiceFactory.getClassTransformerService().getLocalRetransformer().appendClassMethodMatchers(list);
    InstrumentTestUtils.retransformClass(className);
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) LinkedList(java.util.LinkedList)

Example 4 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class InstrumentationMetricsTest method testMultipleMethodTransformationMetrics.

@Test
public void testMultipleMethodTransformationMetrics() throws Exception {
    ServiceFactory.getClassTransformerService().getClassTransformer().getClassNameFilter().addIncludeClass(getClass().getName().replace('.', '/') + "$ClassToRetransform3");
    Map<String, Integer> metricData = InstrumentTestUtils.getAndClearMetricData();
    // This will load the class also:
    String className = ClassToRetransform3Object.class.getName();
    String constructorMetric = MetricNames.SUPPORTABILITY_INIT + className + "/<init>(I)V";
    String methodMetric1 = MetricNames.SUPPORTABILITY_INIT + className + "/getVal()I";
    String methodMetric2 = MetricNames.SUPPORTABILITY_INIT + className + "/getVal2()I";
    Assert.assertEquals(1, new ClassToRetransform3Object(1).getVal());
    Assert.assertEquals(2, new ClassToRetransform3Object(1).getVal2());
    metricData = InstrumentTestUtils.getAndClearMetricData();
    Assert.assertNull(metricData.get(constructorMetric));
    Assert.assertNull(metricData.get(methodMetric1));
    Assert.assertNull(metricData.get(methodMetric2));
    ExtensionClassAndMethodMatcher pc1 = new ExtensionClassAndMethodMatcher(null, null, "Custom", new ExactClassMatcher(className), new AllMethodsMatcher(), false, false, false, false, null);
    List<ExtensionClassAndMethodMatcher> list = new LinkedList<>();
    list.add(pc1);
    ServiceFactory.getClassTransformerService().getLocalRetransformer().appendClassMethodMatchers(list);
    InstrumentTestUtils.retransformClass(className);
    Assert.assertEquals(1, new ClassToRetransform3Object(1).getVal());
    Assert.assertEquals(2, new ClassToRetransform3Object(1).getVal2());
    metricData = InstrumentTestUtils.getAndClearMetricData();
    Assert.assertNull(metricData.get(constructorMetric));
    Assert.assertEquals(Integer.valueOf(1), metricData.get(methodMetric1));
    Assert.assertEquals(Integer.valueOf(1), metricData.get(methodMetric2));
}
Also used : ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) AllMethodsMatcher(com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 5 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class InstrumentationMetricsTest method testMultiplePointcutsTransformationMetrics.

@Test
public void testMultiplePointcutsTransformationMetrics() throws Exception {
    ServiceFactory.getClassTransformerService().getClassTransformer().getClassNameFilter().addIncludeClass(getClass().getName().replace('.', '/') + "$ClassToRetransform2");
    Map<String, Integer> metricData = InstrumentTestUtils.getAndClearMetricData();
    // This will load the class also:
    String className = ClassToRetransform2Object.class.getName();
    String constructorMetric = MetricNames.SUPPORTABILITY_INIT + className + "/<init>(I)V";
    String methodMetric1 = MetricNames.SUPPORTABILITY_INIT + className + "/getVal()I";
    String methodMetric2 = MetricNames.SUPPORTABILITY_INIT + className + "/getVal2()I";
    Assert.assertEquals(1, new ClassToRetransform2Object(1).getVal());
    Assert.assertEquals(2, new ClassToRetransform2Object(1).getVal2());
    metricData = InstrumentTestUtils.getAndClearMetricData();
    Assert.assertNull(metricData.get(constructorMetric));
    Assert.assertNull(metricData.get(methodMetric1));
    Assert.assertNull(metricData.get(methodMetric2));
    ExtensionClassAndMethodMatcher pc1 = new ExtensionClassAndMethodMatcher(null, null, "Custom", new ExactClassMatcher(className), new ExactMethodMatcher("getVal", "()I"), false, false, false, false, null);
    ExtensionClassAndMethodMatcher pc2 = new ExtensionClassAndMethodMatcher(null, null, "Custom", new ExactClassMatcher(className), new ExactMethodMatcher("getVal2", "()I"), false, false, false, false, null);
    List<ExtensionClassAndMethodMatcher> list = new LinkedList<>();
    list.add(pc1);
    list.add(pc2);
    ServiceFactory.getClassTransformerService().getLocalRetransformer().appendClassMethodMatchers(list);
    InstrumentTestUtils.retransformClass(className);
    Assert.assertEquals(1, new ClassToRetransform2Object(1).getVal());
    Assert.assertEquals(2, new ClassToRetransform2Object(1).getVal2());
    metricData = InstrumentTestUtils.getAndClearMetricData();
    Assert.assertNull(metricData.get(constructorMetric));
    Assert.assertEquals(Integer.valueOf(1), metricData.get(methodMetric1));
    Assert.assertEquals(Integer.valueOf(1), metricData.get(methodMetric2));
}
Also used : ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

ExtensionClassAndMethodMatcher (com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher)36 Test (org.junit.Test)26 Extension (com.newrelic.agent.extension.beans.Extension)11 MethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)10 ArrayList (java.util.ArrayList)10 Pointcut (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut)9 Instrumentation (com.newrelic.agent.extension.beans.Extension.Instrumentation)8 File (java.io.File)6 AgentHelper.getFile (com.newrelic.agent.AgentHelper.getFile)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 LinkedList (java.util.LinkedList)5 Method (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method)4 ExactClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher)3 ExactMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher)3 ParameterAttributeName (com.newrelic.agent.instrumentation.tracing.ParameterAttributeName)3 ChildClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ChildClassMatcher)2 ClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ClassMatcher)2 BaseConfig (com.newrelic.agent.config.BaseConfig)1 Config (com.newrelic.agent.config.Config)1 AllClassesMatcher (com.newrelic.agent.instrumentation.classmatchers.AllClassesMatcher)1