Search in sources :

Example 11 with InstrumentedMethod

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

the class WebServiceTest method testTracedInterfaceMethods.

@Test
public void testTracedInterfaceMethods() throws NoSuchMethodException, SecurityException {
    Assert.assertTrue(HelloWorldImpl.class.isAnnotationPresent(InstrumentedClass.class));
    Method method = HelloWorldImpl.class.getMethod("run");
    Assert.assertNotNull(method);
    Assert.assertFalse(method.isAnnotationPresent(InstrumentedMethod.class));
    method = HelloWorldImpl.class.getMethod("getHelloWorld", 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]);
}
Also used : InstrumentedMethod(com.newrelic.agent.instrumentation.InstrumentedMethod) Method(java.lang.reflect.Method) InstrumentedMethod(com.newrelic.agent.instrumentation.InstrumentedMethod) InstrumentedClass(com.newrelic.agent.instrumentation.InstrumentedClass) Test(org.junit.Test)

Example 12 with InstrumentedMethod

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

the class ReinstrumentServiceTest method testInstrumentAnnotation.

@Test
public void testInstrumentAnnotation() throws NoSuchMethodException, SecurityException {
    String transactionMetric1 = "OtherTransaction/Custom/" + InstrumentMeObject.class.getName() + "/aMethod1";
    String methodMetric1 = "Java/" + InstrumentMeObject.class.getName() + "/aMethod1";
    String transactionMetric2 = "OtherTransaction/Custom/" + InstrumentMeObject.class.getName() + "/aMethod2";
    String methodMetric2 = "Java/" + InstrumentMeObject.class.getName() + "/aMethod2";
    String transactionMetric3 = "OtherTransaction/Custom/" + InstrumentMeObject.class.getName() + "/aMethod3";
    String methodMetric3 = "Java/" + InstrumentMeObject.class.getName() + "/aMethod3";
    String methodMetricName = "Java/" + InstrumentMeObject.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=\"test1\">");
    sb.append("<instrumentation>");
    sb.append("<pointcut transactionStartPoint=\"true\">");
    sb.append("<methodAnnotation>com.newrelic.agent.reinstrument.InstrumentAnnotation");
    sb.append("</methodAnnotation>");
    sb.append("</pointcut>");
    sb.append("</instrumentation>");
    sb.append("</extension>");
    InstrumentMeObject obj = new InstrumentMeObject();
    obj.aMethod1();
    obj.aMethod2(5);
    obj.aMethod3("hello");
    InstrumentTestUtils.verifyMetricNotPresent(Arrays.asList(transactionMetric1, methodMetric1, transactionMetric2, methodMetric2, transactionMetric3, methodMetric3));
    // reinstrument for the first time
    ReinstrumentResult result = ServiceFactory.getRemoteInstrumentationService().processXml(sb.toString());
    InstrumentedMethod annotation = InstrumentMeObject.class.getMethod("aMethod1").getAnnotation(InstrumentedMethod.class);
    Assert.assertNotNull(annotation);
    Assert.assertEquals(annotation.instrumentationNames().length, annotation.instrumentationTypes().length);
    Assert.assertEquals(InstrumentationType.RemoteCustomXml, annotation.instrumentationTypes()[0]);
    Assert.assertEquals("test1", annotation.instrumentationNames()[0]);
    obj = new InstrumentMeObject();
    obj.getName("mrs");
    obj.aMethod1();
    obj.aMethod2(5);
    obj.aMethod3("hello");
    // verify result
    Map<String, Object> actual = result.getStatusMap();
    Assert.assertEquals(1, actual.get(ReinstrumentResult.PCS_SPECIFIED_KEY));
    Assert.assertNull(actual.get(ReinstrumentResult.ERROR_KEY));
    // verify metrics
    InstrumentTestUtils.veryPresentNotPresent(Arrays.asList(transactionMetric1, methodMetric1, transactionMetric2, methodMetric2, transactionMetric3, methodMetric3), Arrays.asList(methodMetricName));
}
Also used : InstrumentedMethod(com.newrelic.agent.instrumentation.InstrumentedMethod) Test(org.junit.Test)

Example 13 with InstrumentedMethod

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

the class ReinstrumentAnnotationTest method testAnnotationExludeFromTT.

@Test
public void testAnnotationExludeFromTT() throws NoSuchMethodException, SecurityException {
    String transactionMetric = "OtherTransaction/Custom/" + InstrumentMeObj2.class.getName() + "/getAge";
    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\" excludeFromTransactionTrace=\"true\">");
    sb.append("<className>com.newrelic.agent.reinstrument.InstrumentMeObj2");
    sb.append("</className>");
    sb.append("<method>");
    sb.append("<name>getAge</name>");
    sb.append("<parameters>");
    sb.append("</parameters>");
    sb.append("</method>");
    sb.append("</pointcut>");
    sb.append("</instrumentation>");
    sb.append("</extension>");
    InstrumentMeObj2 obj = new InstrumentMeObj2();
    obj.getAge();
    InstrumentTestUtils.verifyMetricNotPresent(transactionMetric);
    // reinstrument for the first time
    ServiceFactory.getRemoteInstrumentationService().processXml(sb.toString());
    InstrumentedMethod annotation = InstrumentMeObj2.class.getDeclaredMethod("getAge").getAnnotation(InstrumentedMethod.class);
    InstrumentMeObj2 obj1 = new InstrumentMeObj2();
    obj1.getAge();
    InstrumentTestUtils.verifyMetricPresent(transactionMetric);
    Assert.assertNotNull(annotation);
    Assert.assertEquals(annotation.instrumentationNames().length, annotation.instrumentationTypes().length);
    Assert.assertEquals(InstrumentationType.RemoteCustomXml, annotation.instrumentationTypes()[0]);
    Assert.assertEquals("custom xml wahoo", annotation.instrumentationNames()[0]);
    Assert.assertTrue(annotation.dispatcher());
}
Also used : InstrumentedMethod(com.newrelic.agent.instrumentation.InstrumentedMethod) Test(org.junit.Test)

Example 14 with InstrumentedMethod

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

the class ReinstrumentAnnotationTest method testAnnotationMixedInstrumentationTraceXml.

@Test
public void testAnnotationMixedInstrumentationTraceXml() throws ParserConfigurationException, IOException, SAXException, NoSuchMethodException, SecurityException {
    InstrumentMeObj2 obj = new InstrumentMeObj2();
    obj.getHairColor();
    InstrumentedMethod annotation = InstrumentMeObj2.class.getDeclaredMethod("getHairColor").getAnnotation(InstrumentedMethod.class);
    Assert.assertNotNull(annotation);
    Assert.assertEquals(1, annotation.instrumentationTypes().length);
    Assert.assertEquals(InstrumentationType.TraceAnnotation, annotation.instrumentationTypes()[0]);
    Assert.assertEquals("InstrumentMeObj2.java", 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=\"Hairry\">");
    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>getHairColor</name>");
    sb.append("</method>");
    sb.append("</pointcut>");
    sb.append("</instrumentation>");
    sb.append("</extension>");
    // reinstrument for the first time
    ServiceFactory.getRemoteInstrumentationService().processXml(sb.toString());
    annotation = InstrumentMeObj2.class.getDeclaredMethod("getHairColor").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.TraceAnnotation) {
            Assert.assertEquals("InstrumentMeObj2.java", annotation.instrumentationNames()[i]);
        } else if (annotation.instrumentationTypes()[i] == InstrumentationType.RemoteCustomXml) {
            Assert.assertEquals("Hairry", annotation.instrumentationNames()[i]);
        } else {
            Assert.fail("The instrumentation type should be custom yaml or remote custom xml. Type: " + annotation.instrumentationTypes()[i]);
        }
    }
}
Also used : InstrumentedMethod(com.newrelic.agent.instrumentation.InstrumentedMethod) Test(org.junit.Test)

Example 15 with InstrumentedMethod

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

the class ReinstrumentAnnotationTest method testAnnotationMetricNameFormat.

@Test
public void testAnnotationMetricNameFormat() throws NoSuchMethodException, SecurityException {
    String transactionMetric = "OtherTransaction/Custom/hello";
    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=\"foobar\">");
    sb.append("<instrumentation>");
    sb.append("<pointcut transactionStartPoint=\"false\" metricNameFormat=\"hello\">");
    sb.append("<className>com.newrelic.agent.reinstrument.InstrumentMeObj2");
    sb.append("</className>");
    sb.append("<method>");
    sb.append("<name>getShoeSize</name>");
    sb.append("<parameters>");
    sb.append("</parameters>");
    sb.append("</method>");
    sb.append("</pointcut>");
    sb.append("</instrumentation>");
    sb.append("</extension>");
    InstrumentMeObj2 obj = new InstrumentMeObj2();
    obj.getShoeSize();
    InstrumentTestUtils.verifyMetricNotPresent(transactionMetric);
    // reinstrument for the first time
    ServiceFactory.getRemoteInstrumentationService().processXml(sb.toString());
    InstrumentedMethod annotation = InstrumentMeObj2.class.getDeclaredMethod("getShoeSize").getAnnotation(InstrumentedMethod.class);
    InstrumentMeObj2 obj1 = new InstrumentMeObj2();
    obj1.getShoeSize();
    Assert.assertNotNull(annotation);
    Assert.assertEquals(annotation.instrumentationNames().length, annotation.instrumentationTypes().length);
    Assert.assertEquals(InstrumentationType.RemoteCustomXml, annotation.instrumentationTypes()[0]);
    Assert.assertEquals("foobar", annotation.instrumentationNames()[0]);
    Assert.assertFalse(annotation.dispatcher());
}
Also used : InstrumentedMethod(com.newrelic.agent.instrumentation.InstrumentedMethod) Test(org.junit.Test)

Aggregations

InstrumentedMethod (com.newrelic.agent.instrumentation.InstrumentedMethod)18 Test (org.junit.Test)16 Method (java.lang.reflect.Method)8 InstrumentedClass (com.newrelic.agent.instrumentation.InstrumentedClass)3 ArrayList (java.util.ArrayList)2 InstrumentationType (com.newrelic.agent.instrumentation.InstrumentationType)1 PointCut (com.newrelic.agent.instrumentation.PointCut)1 WeavedMethod (com.newrelic.agent.instrumentation.WeavedMethod)1 TraceDetails (com.newrelic.agent.instrumentation.tracing.TraceDetails)1 ExactMethodInfo (com.newrelic.agent.profile.method.ExactMethodInfo)1 MethodInfo (com.newrelic.agent.profile.method.MethodInfo)1 Future (java.util.concurrent.Future)1 Level (java.util.logging.Level)1 ServletConfig (javax.servlet.ServletConfig)1 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpJspPage (javax.servlet.jsp.HttpJspPage)1 SolrCore (org.apache.solr.core.SolrCore)1