Search in sources :

Example 1 with ParameterAttributeName

use of com.newrelic.agent.instrumentation.tracing.ParameterAttributeName 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 ParameterAttributeName

use of com.newrelic.agent.instrumentation.tracing.ParameterAttributeName 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 ParameterAttributeName

use of com.newrelic.agent.instrumentation.tracing.ParameterAttributeName in project newrelic-java-agent by newrelic.

the class ExtensionServiceTest method testParamAttributes.

/**
 * Tests reading in the xml extensions for one file.
 */
@Test
public void testParamAttributes() throws Exception {
    setupFiles(true, XML_FILE_PATH_1);
    ExtensionService extService = new ExtensionService(configService, ExtensionsLoadedListener.NOOP);
    serviceManager.setExtensionService(extService);
    extService.start();
    List<ParameterAttributeName> parameterAttributeNames = null;
    List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
    for (ExtensionClassAndMethodMatcher matcher : pcs) {
        if (matcher.getClassMatcher().getClassNames().contains("test/CustomExtensionTest") && matcher.getMethodMatcher().matches(0, "test2", "(Ljava/lang/String;J)V", null)) {
            parameterAttributeNames = matcher.getTraceDetails().getParameterAttributeNames();
        }
    }
    assertNotNull(parameterAttributeNames);
    assertEquals(2, parameterAttributeNames.size());
}
Also used : ParameterAttributeName(com.newrelic.agent.instrumentation.tracing.ParameterAttributeName) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) Test(org.junit.Test)

Example 4 with ParameterAttributeName

use of com.newrelic.agent.instrumentation.tracing.ParameterAttributeName in project newrelic-java-agent by newrelic.

the class ExtensionConversionUtilityTest method testExtensionConversionUtilityAttributes.

@Test
public void testExtensionConversionUtilityAttributes() throws Exception {
    File file = getFile(FILE_PATH_ATTS);
    Extension extension = ExtensionDomParser.readFile(file);
    Assert.assertNotNull(extension);
    // default is to include atts
    List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToEnabledPointCuts(toList(extension), true, InstrumentationType.RemoteCustomXml);
    Assert.assertNotNull(pcs);
    Assert.assertEquals(1, pcs.size());
    List<ParameterAttributeName> actualAtts = pcs.get(0).getTraceDetails().getParameterAttributeNames();
    verifyAttNames(actualAtts, Arrays.asList("param1", "param2", "reportMe"));
    pcs = ExtensionConversionUtility.convertToEnabledPointCuts(toList(extension), true, InstrumentationType.RemoteCustomXml, true);
    actualAtts = pcs.get(0).getTraceDetails().getParameterAttributeNames();
    verifyAttNames(actualAtts, Arrays.asList("param1", "param2", "reportMe"));
    pcs = ExtensionConversionUtility.convertToEnabledPointCuts(toList(extension), true, InstrumentationType.RemoteCustomXml, false);
    actualAtts = pcs.get(0).getTraceDetails().getParameterAttributeNames();
    Assert.assertEquals(0, actualAtts.size());
}
Also used : Extension(com.newrelic.agent.extension.beans.Extension) ParameterAttributeName(com.newrelic.agent.instrumentation.tracing.ParameterAttributeName) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) AgentHelper.getFile(com.newrelic.agent.AgentHelper.getFile) File(java.io.File) Test(org.junit.Test)

Aggregations

ExtensionClassAndMethodMatcher (com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher)4 ParameterAttributeName (com.newrelic.agent.instrumentation.tracing.ParameterAttributeName)4 Extension (com.newrelic.agent.extension.beans.Extension)2 AnnotationMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher)2 LambdaMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.LambdaMethodMatcher)2 MethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)2 ReturnTypeMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ReturnTypeMethodMatcher)2 Test (org.junit.Test)2 AgentHelper.getFile (com.newrelic.agent.AgentHelper.getFile)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 ChildClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ChildClassMatcher)1 ClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ClassMatcher)1 ExactClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1