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