Search in sources :

Example 16 with TracedMetricData

use of com.newrelic.agent.introspec.TracedMetricData in project newrelic-java-agent by newrelic.

the class HandlerTracingTest method testLambdaNames.

@Test
public void testLambdaNames() {
    Vertx vertx = Vertx.vertx();
    try {
        Router router = Router.router(vertx);
        router.route().path("/products").handler(ProductHandlers::getAllProducts);
        router.route().path("/product/:pid").handler(ProductHandlers.getProductHandler());
        HttpServer server = createServer(vertx, router);
        getRequest("/products/", server).then().statusCode(200);
        Map<String, TracedMetricData> metrics = getMetrics("OtherTransaction/Vertx/products (GET)");
        assertTrue(metrics.containsKey("com.nr.vertx.instrumentation.HandlerTracingTest.lambda()"));
        InstrumentationTestRunner.getIntrospector().clear();
        getRequest("/product/milk", server).then().statusCode(200);
        metrics = getMetrics("OtherTransaction/Vertx/product/:pid (GET)");
        assertTrue(metrics.containsKey("com.nr.vertx.test.handlers.ProductHandlers.lambda()"));
        InstrumentationTestRunner.getIntrospector().clear();
    } finally {
        vertx.close();
    }
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) HttpServer(io.vertx.core.http.HttpServer) Router(io.vertx.ext.web.Router) ProductHandlers(com.nr.vertx.test.handlers.ProductHandlers) Vertx(io.vertx.core.Vertx) Test(org.junit.Test)

Example 17 with TracedMetricData

use of com.newrelic.agent.introspec.TracedMetricData in project newrelic-java-agent by newrelic.

the class IntrospectorImplTest method testOneTracerInTransaction.

@Test
public void testOneTracerInTransaction() {
    // transaction
    Transaction.getTransaction();
    long startNs = System.nanoTime();
    Tracer rootTracer = createOtherTracer("rootOnly");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
    rootTracer.finish(RETURN_OPCODE, 0);
    long diffNsRootOnly = System.nanoTime() - startNs;
    // data check
    Collection<String> txNames = impl.getTransactionNames();
    Assert.assertEquals(1, txNames.size());
    Assert.assertEquals("OtherTransaction/rootOnly", txNames.iterator().next());
    Map<String, TracedMetricData> metrics = impl.getMetricsForTransaction("OtherTransaction/rootOnly");
    Assert.assertEquals(1, metrics.size());
    TracedMetricData data = metrics.get("Java/java.lang.Object/rootOnly");
    Assert.assertEquals("Java/java.lang.Object/rootOnly", data.getName());
    Assert.assertEquals(1, data.getCallCount());
    Assert.assertEquals(data.getTotalTimeInSec(), data.getExclusiveTimeInSec(), .000000001);
    Assert.assertTrue(data.getTotalTimeInSec() < (diffNsRootOnly / 1000000000.0));
    Collection<com.newrelic.agent.introspec.TransactionEvent> events = impl.getTransactionEvents("OtherTransaction/rootOnly");
    Assert.assertNotNull(events);
    Assert.assertEquals(1, events.size());
    com.newrelic.agent.introspec.TransactionEvent event = events.iterator().next();
    Assert.assertEquals("OtherTransaction/rootOnly", event.getName());
    Assert.assertEquals(0, event.getDatabaseCallCount(), .00001);
    Assert.assertEquals(0, event.getExternalCallCount(), .00001);
    Assert.assertEquals(event.getDurationInSec(), data.getTotalTimeInSec(), .00000001);
    Assert.assertEquals(event.getDurationInSec(), event.getTotalTimeInSec(), .0000001);
    Map<String, TracedMetricData> unscoped = impl.getUnscopedMetrics();
    Assert.assertNotNull(unscoped);
    TracedMetricData stats = unscoped.get("OtherTransactionTotalTime");
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, stats.getCallCount());
    Assert.assertEquals(event.getDurationInSec(), stats.getTotalTimeInSec(), .0000001);
    stats = unscoped.get("OtherTransactionTotalTime/rootOnly");
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, stats.getCallCount());
    Assert.assertEquals(event.getDurationInSec(), stats.getTotalTimeInSec(), .0000001);
    stats = unscoped.get("OtherTransaction/rootOnly");
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, stats.getCallCount());
    Assert.assertEquals(event.getDurationInSec(), stats.getTotalTimeInSec(), .0000001);
    stats = unscoped.get("OtherTransaction/all");
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, stats.getCallCount());
    Assert.assertEquals(event.getDurationInSec(), stats.getTotalTimeInSec(), .0000001);
    // second transaction
    startNs = System.nanoTime();
    rootTracer = createOtherTracer("secondTransaction");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
    rootTracer.finish(RETURN_OPCODE, 0);
    long diffNsSecondTransaction = System.nanoTime() - startNs;
    // data check
    txNames = impl.getTransactionNames();
    Assert.assertEquals(2, txNames.size());
    metrics = impl.getMetricsForTransaction("OtherTransaction/rootOnly");
    Assert.assertEquals(1, metrics.size());
    data = metrics.get("Java/java.lang.Object/rootOnly");
    Assert.assertEquals("Java/java.lang.Object/rootOnly", data.getName());
    Assert.assertEquals(1, data.getCallCount());
    Assert.assertEquals(data.getTotalTimeInSec(), data.getExclusiveTimeInSec(), .000000001);
    final double diffInSeconds = diffNsRootOnly / 1000000000.0;
    final String msg = "Total duration in seconds is greater than diff. Duration in sec " + data.getTotalTimeInSec() + " diff: " + diffInSeconds;
    Assert.assertTrue(msg, data.getTotalTimeInSec() < diffInSeconds);
    metrics = impl.getMetricsForTransaction("OtherTransaction/secondTransaction");
    Assert.assertEquals(1, metrics.size());
    data = metrics.get("Java/java.lang.Object/secondTransaction");
    Assert.assertEquals("Java/java.lang.Object/secondTransaction", data.getName());
    Assert.assertEquals(1, data.getCallCount());
    Assert.assertEquals(data.getTotalTimeInSec(), data.getExclusiveTimeInSec(), .000000001);
    Assert.assertTrue(data.getTotalTimeInSec() < (diffNsSecondTransaction / 1000000000.0));
    events = impl.getTransactionEvents("OtherTransaction/secondTransaction");
    Assert.assertNotNull(events);
    Assert.assertEquals(1, events.size());
    event = events.iterator().next();
    Assert.assertEquals("OtherTransaction/secondTransaction", event.getName());
    Assert.assertEquals(0, event.getDatabaseCallCount(), .00001);
    Assert.assertEquals(0, event.getExternalCallCount(), .00001);
    Assert.assertEquals(event.getDurationInSec(), data.getTotalTimeInSec(), .00000001);
    Assert.assertEquals(event.getDurationInSec(), event.getTotalTimeInSec(), .0000001);
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 18 with TracedMetricData

use of com.newrelic.agent.introspec.TracedMetricData in project newrelic-java-agent by newrelic.

the class IntrospectorImplTest method testUnscopedOutsideTransaction.

@Test
public void testUnscopedOutsideTransaction() {
    ServiceFactory.getStatsService().getMetricAggregator().incrementCounter("MyCounter11");
    ServiceFactory.getStatsService().getMetricAggregator().recordMetric("MyRecordMetric", 5.33f);
    ServiceFactory.getStatsService().getMetricAggregator().recordResponseTimeMetric("MyResponse/Time", 5000);
    // data check
    Map<String, TracedMetricData> unscoped = impl.getUnscopedMetrics();
    Assert.assertNotNull(unscoped);
    TracedMetricData stats = unscoped.get("MyCounter11");
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, stats.getCallCount());
    Assert.assertEquals(0, stats.getTotalTimeInSec(), .0000001);
    stats = unscoped.get("MyRecordMetric");
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, stats.getCallCount());
    Assert.assertEquals(5.33f, stats.getTotalTimeInSec(), .001);
    stats = unscoped.get("MyResponse/Time");
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, stats.getCallCount());
    Assert.assertEquals(5, stats.getTotalTimeInSec(), .001);
    // add data again
    ServiceFactory.getStatsService().getMetricAggregator().incrementCounter("MyCounter11");
    ServiceFactory.getStatsService().getMetricAggregator().recordMetric("MyRecordMetric", 5.22f);
    ServiceFactory.getStatsService().getMetricAggregator().recordResponseTimeMetric("MyResponse/Time", 7000);
    ServiceFactory.getStatsService().getMetricAggregator().recordResponseTimeMetric("MyResponse/Time", 7000);
    // data check
    unscoped = impl.getUnscopedMetrics();
    Assert.assertNotNull(unscoped);
    stats = unscoped.get("MyCounter11");
    Assert.assertNotNull(stats);
    Assert.assertEquals(2, stats.getCallCount());
    Assert.assertEquals(0, stats.getTotalTimeInSec(), .0000001);
    stats = unscoped.get("MyRecordMetric");
    Assert.assertNotNull(stats);
    Assert.assertEquals(2, stats.getCallCount());
    Assert.assertEquals(10.55f, stats.getTotalTimeInSec(), .001);
    stats = unscoped.get("MyResponse/Time");
    Assert.assertNotNull(stats);
    Assert.assertEquals(3, stats.getCallCount());
    Assert.assertEquals(19, stats.getTotalTimeInSec(), .001);
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) Test(org.junit.Test)

Example 19 with TracedMetricData

use of com.newrelic.agent.introspec.TracedMetricData in project newrelic-java-agent by newrelic.

the class IntrospectorImplTest method testMultChildrenTransaction.

@Test
public void testMultChildrenTransaction() {
    // transaction
    Transaction.getTransaction();
    long startNs = System.nanoTime();
    Tracer rootTracer = createOtherTracer("rootOnly");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
    Tracer child1 = createDefaultTracer("default1");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child1);
    Tracer child2 = createDefaultTracer("default2");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child2);
    child2.finish(RETURN_OPCODE, 0);
    child1.finish(RETURN_OPCODE, 0);
    rootTracer.finish(RETURN_OPCODE, 0);
    long diffNs = System.nanoTime() - startNs;
    // data check
    Collection<String> txNames = impl.getTransactionNames();
    Assert.assertEquals(1, txNames.size());
    Assert.assertEquals("OtherTransaction/rootOnly", txNames.iterator().next());
    Map<String, TracedMetricData> metrics = impl.getMetricsForTransaction("OtherTransaction/rootOnly");
    Assert.assertEquals(3, metrics.size());
    TracedMetricData init = metrics.get("Java/java.lang.Object/rootOnly");
    Assert.assertNotNull(init);
    Assert.assertEquals("Java/java.lang.Object/rootOnly", init.getName());
    Assert.assertEquals(1, init.getCallCount());
    Assert.assertTrue(init.getTotalTimeInSec() > init.getExclusiveTimeInSec());
    Assert.assertTrue(init.getTotalTimeInSec() < (diffNs / 1000000000.0));
    TracedMetricData data1 = metrics.get("Custom/default1");
    Assert.assertNotNull(data1);
    Assert.assertEquals("Custom/default1", data1.getName());
    Assert.assertEquals(1, data1.getCallCount());
    Assert.assertNotEquals(data1.getTotalTimeInSec(), data1.getExclusiveTimeInSec(), .000000001);
    Assert.assertTrue(data1.getTotalTimeInSec() < init.getTotalTimeInSec());
    TracedMetricData data2 = metrics.get("Custom/default2");
    Assert.assertNotNull(data2);
    Assert.assertEquals("Custom/default2", data2.getName());
    Assert.assertEquals(1, data2.getCallCount());
    Assert.assertEquals(data2.getTotalTimeInSec(), data2.getExclusiveTimeInSec(), .000000001);
    Assert.assertEquals(data2.getTotalTimeInSec(), (data1.getTotalTimeInSec() - data1.getExclusiveTimeInSec()), .00000001);
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 20 with TracedMetricData

use of com.newrelic.agent.introspec.TracedMetricData in project newrelic-java-agent by newrelic.

the class IntrospectorImplTest method testMultipleTracersInTransaction.

@Test
public void testMultipleTracersInTransaction() {
    // transaction
    Transaction.getTransaction();
    long startNs = System.nanoTime();
    Tracer rootTracer = createOtherTracer("rootOnly1");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
    Tracer child1 = createDefaultTracer("default1");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child1);
    child1.finish(RETURN_OPCODE, 0);
    child1 = createDefaultTracer("default1");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child1);
    child1.finish(RETURN_OPCODE, 0);
    rootTracer.finish(RETURN_OPCODE, 0);
    long diffNs = System.nanoTime() - startNs;
    // data check
    Collection<String> txNames = impl.getTransactionNames();
    Assert.assertEquals(1, txNames.size());
    Assert.assertEquals("OtherTransaction/rootOnly1", txNames.iterator().next());
    Map<String, TracedMetricData> metrics = impl.getMetricsForTransaction("OtherTransaction/rootOnly1");
    Assert.assertEquals(2, metrics.size());
    TracedMetricData data = metrics.get("Java/java.lang.Object/rootOnly1");
    Assert.assertNotNull(data);
    Assert.assertEquals("Java/java.lang.Object/rootOnly1", data.getName());
    Assert.assertEquals(1, data.getCallCount());
    Assert.assertTrue(data.getTotalTimeInSec() > data.getExclusiveTimeInSec());
    Assert.assertTrue(data.getTotalTimeInSec() < (diffNs / 1000000000.0));
    data = metrics.get("Custom/default1");
    Assert.assertNotNull(data);
    Assert.assertEquals("Custom/default1", data.getName());
    Assert.assertEquals(2, data.getCallCount());
    Assert.assertEquals(data.getTotalTimeInSec(), data.getExclusiveTimeInSec(), .000000001);
    Assert.assertTrue(data.getTotalTimeInSec() < (diffNs / 1000000000.0));
    // second transaction - same as first
    Transaction.clearTransaction();
    Transaction.getTransaction();
    rootTracer = createOtherTracer("rootOnly1");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
    child1 = createDefaultTracer("default1");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child1);
    child1.finish(RETURN_OPCODE, 0);
    child1 = createDefaultTracer("default1");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child1);
    child1.finish(RETURN_OPCODE, 0);
    rootTracer.finish(RETURN_OPCODE, 0);
    // data check
    Assert.assertEquals(2, impl.getFinishedTransactionCount());
    txNames = impl.getTransactionNames();
    Assert.assertEquals(1, txNames.size());
    Assert.assertEquals("OtherTransaction/rootOnly1", txNames.iterator().next());
    metrics = impl.getMetricsForTransaction("OtherTransaction/rootOnly1");
    Assert.assertEquals(2, metrics.size());
    data = metrics.get("Java/java.lang.Object/rootOnly1");
    Assert.assertNotNull(data);
    Assert.assertEquals("Java/java.lang.Object/rootOnly1", data.getName());
    Assert.assertEquals(2, data.getCallCount());
    Assert.assertTrue(data.getTotalTimeInSec() > data.getExclusiveTimeInSec());
    data = metrics.get("Custom/default1");
    Assert.assertNotNull(data);
    Assert.assertEquals("Custom/default1", data.getName());
    Assert.assertEquals(4, data.getCallCount());
    Assert.assertEquals(data.getTotalTimeInSec(), data.getExclusiveTimeInSec(), .000000001);
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Aggregations

TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)65 Test (org.junit.Test)58 Introspector (com.newrelic.agent.introspec.Introspector)51 Java7IncompatibleTest (com.newrelic.test.marker.Java7IncompatibleTest)15 URI (java.net.URI)12 TransactionEvent (com.newrelic.agent.introspec.TransactionEvent)10 ExternalRequest (com.newrelic.agent.introspec.ExternalRequest)7 Tracer (com.newrelic.agent.tracers.Tracer)7 TransactionTrace (com.newrelic.agent.introspec.TransactionTrace)6 AMQP (com.rabbitmq.client.AMQP)6 DefaultConsumer (com.rabbitmq.client.DefaultConsumer)6 Envelope (com.rabbitmq.client.Envelope)6 IOException (java.io.IOException)6 ActorSystem (akka.actor.ActorSystem)5 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)4 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)4 Vertx (io.vertx.core.Vertx)4 HttpServer (io.vertx.core.http.HttpServer)4 TraceSegment (com.newrelic.agent.introspec.TraceSegment)3 Trace (com.newrelic.api.agent.Trace)3