use of com.newrelic.agent.instrumentation.InstrumentedMethod in project newrelic-java-agent by newrelic.
the class ProfiledMethodFactory method getMethodInfo.
public MethodInfo getMethodInfo(ClassMethodSignature methodSignature) {
MethodInfo methodInfo = methodInfos.get(methodSignature);
if (null == methodInfo) {
Type[] argumentTypes = Type.getArgumentTypes(methodSignature.getMethodDesc());
List<String> arguments = new ArrayList<>(argumentTypes.length);
for (Type t : argumentTypes) {
arguments.add(t.getClassName());
}
methodInfo = new ExactMethodInfo(arguments, (InstrumentedMethod) null);
MethodInfo previous = methodInfos.putIfAbsent(methodSignature, methodInfo);
if (previous != null) {
return previous;
}
}
return methodInfo;
}
use of com.newrelic.agent.instrumentation.InstrumentedMethod in project newrelic-java-agent by newrelic.
the class WebServiceTest method testTracedMethods.
@Test
public void testTracedMethods() throws NoSuchMethodException, SecurityException {
Assert.assertTrue(WsExample.class.isAnnotationPresent(InstrumentedClass.class));
Method method = WsExample.class.getMethod("run");
Assert.assertNotNull(method);
Assert.assertFalse(method.isAnnotationPresent(InstrumentedMethod.class));
method = WsExample.class.getMethod("getWebMethod", String.class);
Assert.assertNotNull(method);
Assert.assertTrue(method.isAnnotationPresent(InstrumentedMethod.class));
InstrumentedMethod annotation = method.getAnnotation(InstrumentedMethod.class);
Assert.assertEquals("com.newrelic.agent.instrumentation.webservices.WebServiceVisitor", annotation.instrumentationNames()[0]);
Assert.assertEquals(InstrumentationType.BuiltIn, annotation.instrumentationTypes()[0]);
}
use of com.newrelic.agent.instrumentation.InstrumentedMethod in project newrelic-java-agent by newrelic.
the class ReinstrumentAnnotationTest method testAnnotation.
@Test
public void testAnnotation() throws NoSuchMethodException, SecurityException {
String transactionMetric = "OtherTransaction/Custom/" + InstrumentMeObj2.class.getName() + "/getName";
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
sb.append("<extension xmlns=\"https://newrelic.com/docs/java/xsd/v1.0\"");
sb.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
sb.append(" xsi:schemaLocation=\"newrelic-extension extension.xsd \" name=\"testing 123\">");
sb.append("<instrumentation>");
sb.append("<pointcut transactionStartPoint=\"true\">");
sb.append("<className>com.newrelic.agent.reinstrument.InstrumentMeObj2");
sb.append("</className>");
sb.append("<method>");
sb.append("<name>getName</name>");
sb.append("<parameters>");
sb.append("<type>java.lang.String</type>");
sb.append("</parameters>");
sb.append("</method>");
sb.append("</pointcut>");
sb.append("</instrumentation>");
sb.append("</extension>");
InstrumentMeObj2 obj = new InstrumentMeObj2();
obj.getName("mr");
InstrumentTestUtils.verifyMetricNotPresent(transactionMetric);
// reinstrument for the first time
ServiceFactory.getRemoteInstrumentationService().processXml(sb.toString());
InstrumentedMethod annotation = InstrumentMeObj2.class.getDeclaredMethod("getName", String.class).getAnnotation(InstrumentedMethod.class);
Assert.assertNotNull(annotation);
Assert.assertEquals(annotation.instrumentationNames().length, annotation.instrumentationTypes().length);
Assert.assertEquals(InstrumentationType.RemoteCustomXml, annotation.instrumentationTypes()[0]);
Assert.assertEquals("testing 123", annotation.instrumentationNames()[0]);
Assert.assertTrue(annotation.dispatcher());
}
use of com.newrelic.agent.instrumentation.InstrumentedMethod in project newrelic-java-agent by newrelic.
the class ReinstrumentAnnotationTest method testWeavePlusXml.
@Test
public void testWeavePlusXml() throws NoSuchMethodException, SecurityException {
class JspTest implements HttpJspPage {
@Override
public void jspDestroy() {
}
@Override
public void jspInit() {
}
@Override
public void init(ServletConfig config) throws ServletException {
}
@Override
public ServletConfig getServletConfig() {
return null;
}
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
}
@Override
public String getServletInfo() {
return null;
}
@Override
public void destroy() {
}
@Override
public void _jspService(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
}
}
JspTest test = new JspTest();
InstrumentedMethod annotation = JspTest.class.getDeclaredMethod("_jspService", HttpServletRequest.class, HttpServletResponse.class).getAnnotation(InstrumentedMethod.class);
Assert.assertNotNull(annotation);
Assert.assertEquals(2, annotation.instrumentationTypes().length);
for (int i = 0; i < annotation.instrumentationTypes().length; i++) {
Assert.assertEquals("com.newrelic.instrumentation.jsp-2.4", annotation.instrumentationNames()[i]);
Assert.assertTrue(annotation.instrumentationTypes()[i] == InstrumentationType.TracedWeaveInstrumentation || annotation.instrumentationTypes()[i] == InstrumentationType.WeaveInstrumentation);
}
// reinstrument with more instrumentation
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
sb.append("<extension xmlns=\"https://newrelic.com/docs/java/xsd/v1.0\"");
sb.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
sb.append(" xsi:schemaLocation=\"newrelic-extension extension.xsd \" name=\"Not A Pointcut\">");
sb.append("<instrumentation>");
sb.append("<pointcut transactionStartPoint=\"true\" >");
sb.append("<className>" + JspTest.class.getName());
sb.append("</className>");
sb.append("<method>");
sb.append("<name>_jspService</name>");
sb.append("</method>");
sb.append("</pointcut>");
sb.append("</instrumentation>");
sb.append("</extension>");
// reinstrument for the first time
ServiceFactory.getRemoteInstrumentationService().processXml(sb.toString());
annotation = JspTest.class.getDeclaredMethod("_jspService", HttpServletRequest.class, HttpServletResponse.class).getAnnotation(InstrumentedMethod.class);
Assert.assertNotNull(annotation);
Assert.assertEquals(3, annotation.instrumentationTypes().length);
for (int i = 0; i < annotation.instrumentationTypes().length; i++) {
if (annotation.instrumentationNames()[i].equals("com.newrelic.instrumentation.jsp-2.4")) {
Assert.assertTrue(annotation.instrumentationTypes()[i] == InstrumentationType.TracedWeaveInstrumentation || annotation.instrumentationTypes()[i] == InstrumentationType.WeaveInstrumentation);
} else if (annotation.instrumentationNames()[i].equals("Not A Pointcut")) {
Assert.assertTrue(annotation.instrumentationTypes()[i] == InstrumentationType.RemoteCustomXml);
} else {
Assert.fail("The instrumentation name does not match. Name: " + annotation.instrumentationNames()[i]);
}
}
}
use of com.newrelic.agent.instrumentation.InstrumentedMethod in project newrelic-java-agent by newrelic.
the class ReinstrumentAnnotationTest method testAnnotationMixedInstrumentationYamlXml.
@Test
public void testAnnotationMixedInstrumentationYamlXml() throws ParserConfigurationException, IOException, SAXException, NoSuchMethodException, SecurityException {
ServiceFactory.getStatsService().getStatsEngineForHarvest(null).clear();
Method method = SolrCore.class.getDeclaredMethod("getSearcher", boolean.class, boolean.class, Future[].class);
InstrumentedMethod annotation = method.getAnnotation(InstrumentedMethod.class);
Assert.assertNotNull(annotation);
Assert.assertEquals(1, annotation.instrumentationTypes().length);
Assert.assertEquals(InstrumentationType.CustomYaml, annotation.instrumentationTypes()[0]);
Assert.assertEquals("Solr", annotation.instrumentationNames()[0]);
// reinstrument with more instrumentation
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
sb.append("<extension xmlns=\"https://newrelic.com/docs/java/xsd/v1.0\"");
sb.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
sb.append(" xsi:schemaLocation=\"newrelic-extension extension.xsd \" name=\"MySecondSolr\">");
sb.append("<instrumentation>");
sb.append("<pointcut transactionStartPoint=\"true\" >");
sb.append("<className>org.apache.solr.core.SolrCore");
sb.append("</className>");
sb.append("<method>");
sb.append("<name>getSearcher</name>");
sb.append("</method>");
sb.append("</pointcut>");
sb.append("</instrumentation>");
sb.append("</extension>");
// reinstrument for the first time
ServiceFactory.getRemoteInstrumentationService().processXml(sb.toString());
method = SolrCore.class.getDeclaredMethod("getSearcher", boolean.class, boolean.class, Future[].class);
annotation = method.getAnnotation(InstrumentedMethod.class);
Assert.assertNotNull(annotation);
Assert.assertEquals(2, annotation.instrumentationTypes().length);
for (int i = 0; i < annotation.instrumentationTypes().length; i++) {
if (annotation.instrumentationTypes()[i] == InstrumentationType.CustomYaml) {
Assert.assertEquals("Solr", annotation.instrumentationNames()[i]);
} else if (annotation.instrumentationTypes()[i] == InstrumentationType.RemoteCustomXml) {
Assert.assertEquals("MySecondSolr", annotation.instrumentationNames()[i]);
} else {
Assert.fail("The instrumentation type should be custom yaml or remote custom xml. Type: " + annotation.instrumentationTypes()[i]);
}
}
}
Aggregations