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;
}
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);
}
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());
}
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());
}
Aggregations