use of com.newrelic.agent.instrumentation.InstrumentedMethod in project newrelic-java-agent by newrelic.
the class ReinstrumentAnnotationTest method testXmlPlusPointCut.
@Test
public void testXmlPlusPointCut() throws NoSuchMethodException, SecurityException {
RpcCall rpcCall = new RpcCall();
InstrumentedMethod annotation = test.newrelic.test.agent.RpcCall.class.getDeclaredMethod("invoke", Object[].class).getAnnotation(InstrumentedMethod.class);
Assert.assertNotNull(annotation);
Assert.assertEquals(1, annotation.instrumentationTypes().length);
Assert.assertEquals(InstrumentationType.Pointcut, annotation.instrumentationTypes()[0]);
Assert.assertEquals("com.newrelic.agent.instrumentation.pointcuts.XmlRpcPointCut", 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=\"Not A Pointcut\">");
sb.append("<instrumentation>");
sb.append("<pointcut transactionStartPoint=\"true\" >");
sb.append("<className>test.newrelic.test.agent.RpcCall");
sb.append("</className>");
sb.append("<method>");
sb.append("<name>invoke</name>");
sb.append("</method>");
sb.append("</pointcut>");
sb.append("</instrumentation>");
sb.append("</extension>");
// reinstrument for the first time
ServiceFactory.getRemoteInstrumentationService().processXml(sb.toString());
annotation = test.newrelic.test.agent.RpcCall.class.getDeclaredMethod("invoke", Object[].class).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.Pointcut) {
Assert.assertEquals("com.newrelic.agent.instrumentation.pointcuts.XmlRpcPointCut", annotation.instrumentationNames()[i]);
} else if (annotation.instrumentationTypes()[i] == InstrumentationType.RemoteCustomXml) {
Assert.assertEquals("Not A Pointcut", annotation.instrumentationNames()[i]);
} else {
Assert.fail("The instrumentation type should be custom yaml or remote custom xml. Type: " + annotation.instrumentationTypes()[i]);
}
}
}
use of com.newrelic.agent.instrumentation.InstrumentedMethod in project newrelic-java-agent by newrelic.
the class ReinstrumentAnnotationTest method testAnnotationIgnore.
@Test
public void testAnnotationIgnore() throws NoSuchMethodException, SecurityException {
String transactionMetric = "OtherTransaction/Custom/" + InstrumentMeObj2.class.getName() + "/getSecondAge";
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=\"custom xml wahoo\">");
sb.append("<instrumentation>");
sb.append("<pointcut transactionStartPoint=\"true\" ignoreTransaction=\"true\">");
sb.append("<className>com.newrelic.agent.reinstrument.InstrumentMeObj2");
sb.append("</className>");
sb.append("<method>");
sb.append("<name>getSecondAge</name>");
sb.append("<parameters>");
sb.append("</parameters>");
sb.append("</method>");
sb.append("</pointcut>");
sb.append("</instrumentation>");
sb.append("</extension>");
InstrumentMeObj2 obj = new InstrumentMeObj2();
obj.getSecondAge();
InstrumentTestUtils.verifyMetricNotPresent(transactionMetric);
// reinstrument for the first time
ServiceFactory.getRemoteInstrumentationService().processXml(sb.toString());
InstrumentedMethod annotation = InstrumentMeObj2.class.getDeclaredMethod("getSecondAge").getAnnotation(InstrumentedMethod.class);
InstrumentMeObj2 obj1 = new InstrumentMeObj2();
obj1.getSecondAge();
InstrumentTestUtils.verifyMetricNotPresent(transactionMetric);
// no annotation for ignored methods
Assert.assertNull(annotation);
}
use of com.newrelic.agent.instrumentation.InstrumentedMethod in project newrelic-java-agent by newrelic.
the class TraceAnnotationTest method testInstrumentedMethodMarker.
@Test
public void testInstrumentedMethodMarker() throws SecurityException, NoSuchMethodException {
Method method = Simple.class.getDeclaredMethod("foo");
InstrumentedMethod annotation = method.getAnnotation(InstrumentedMethod.class);
Assert.assertNotNull(annotation);
Assert.assertEquals(InstrumentationType.TraceAnnotation, annotation.instrumentationTypes()[0]);
Assert.assertEquals("TraceAnnotationTest.java", annotation.instrumentationNames()[0]);
}
Aggregations