Search in sources :

Example 46 with TracedMetricData

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

the class JaxRsTests method testTransactionNameInterface.

@Test
public void testTransactionNameInterface() {
    assertEquals("Got it from the interface!", App.callInterfaceResourceInTransaction());
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    String expectedTransactionName = "OtherTransaction/RestWebService/interface (GET)";
    Map<String, TracedMetricData> metricsForTransaction = introspector.getMetricsForTransaction(expectedTransactionName);
    assertEquals(1, metricsForTransaction.get("Java/com.nr.instrumentation.javax.ws.rs.api.InterfaceResourceImpl/getIt").getCallCount());
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) Introspector(com.newrelic.agent.introspec.Introspector) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest) Test(org.junit.Test)

Example 47 with TracedMetricData

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

the class IntrospectorImplTest method testUnscopedInTransaction.

@Test
public void testUnscopedInTransaction() {
    // transaction
    Transaction.getTransaction();
    Tracer rootTracer = createOtherTracer("rootOnly");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
    Transaction.getTransaction().getMetricAggregator().incrementCounter("MyCounter");
    ServiceFactory.getStatsService().getMetricAggregator().incrementCounter("MySecondCounter");
    rootTracer.finish(RETURN_OPCODE, 0);
    // data check
    Map<String, TracedMetricData> unscoped = impl.getUnscopedMetrics();
    Assert.assertNotNull(unscoped);
    TracedMetricData stats = unscoped.get("MyCounter");
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, stats.getCallCount());
    Assert.assertEquals(0, stats.getTotalTimeInSec(), .0000001);
    stats = unscoped.get("MySecondCounter");
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, stats.getCallCount());
    Assert.assertEquals(0, stats.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 48 with TracedMetricData

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

the class TransactionTraceTest method testOneTracerInTransaction.

@Test
public void testOneTracerInTransaction() {
    // transaction
    long start = System.currentTimeMillis();
    Transaction.getTransaction();
    Tracer rootTracer = IntrospectorImplTest.createOtherTracer("rootOnly");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
    rootTracer.finish(Opcodes.RETURN, 0);
    long end = System.currentTimeMillis();
    // data check
    Map<String, TracedMetricData> metrics = impl.getUnscopedMetrics();
    TracedMetricData txMetric = metrics.get("OtherTransaction/rootOnly");
    Collection<TransactionTrace> traces = impl.getTransactionTracesForTransaction("OtherTransaction/rootOnly");
    Assert.assertEquals(1, traces.size());
    TransactionTrace trace = traces.iterator().next();
    Assert.assertEquals(txMetric.getTotalTimeInSec(), trace.getResponseTimeInSec(), .01);
    Assert.assertEquals(trace.getWallClockDurationInSec(), trace.getResponseTimeInSec(), .01);
    Assert.assertTrue(trace.getStartTime() >= start);
    Assert.assertTrue(trace.getStartTime() <= end);
    TraceSegment segment = trace.getInitialTraceSegment();
    Assert.assertEquals(0, segment.getChildren().size());
    Map<String, Object> info = segment.getTracerAttributes();
    Assert.assertNotNull(info.get("async_context"));
    Assert.assertNotNull(info.get("exclusive_duration_millis"));
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) Tracer(com.newrelic.agent.tracers.Tracer) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) TraceSegment(com.newrelic.agent.introspec.TraceSegment) Test(org.junit.Test)

Example 49 with TracedMetricData

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

the class TransactionTraceTest method testOneTracerInTransactionWithChildren.

@Test
public void testOneTracerInTransactionWithChildren() {
    // transaction
    long start = System.currentTimeMillis();
    Transaction.getTransaction();
    Tracer rootTracer = IntrospectorImplTest.createOtherTracer("rootOnly");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
    Tracer child1 = IntrospectorImplTest.createDefaultTracer("default1");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child1);
    child1.finish(Opcodes.RETURN, 0);
    Tracer child2 = IntrospectorImplTest.createDefaultTracer("default2");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child2);
    child2.finish(Opcodes.RETURN, 0);
    Tracer child3 = IntrospectorImplTest.createDefaultTracer("default3");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child3);
    child3.setAgentAttribute("myatt", "hello");
    child3.setAgentAttribute("myNumber", 99);
    child3.finish(Opcodes.RETURN, 0);
    rootTracer.finish(Opcodes.RETURN, 0);
    long end = System.currentTimeMillis();
    // data check
    Assert.assertEquals(1, impl.getFinishedTransactionCount());
    Map<String, TracedMetricData> metrics = impl.getUnscopedMetrics();
    TracedMetricData txMetric = metrics.get("OtherTransaction/rootOnly");
    Collection<TransactionTrace> traces = impl.getTransactionTracesForTransaction("OtherTransaction/rootOnly");
    Assert.assertEquals(1, traces.size());
    TransactionTrace trace = traces.iterator().next();
    Assert.assertEquals(txMetric.getTotalTimeInSec(), trace.getResponseTimeInSec(), .01);
    Assert.assertEquals(trace.getWallClockDurationInSec(), trace.getResponseTimeInSec(), .01);
    Assert.assertTrue(trace.getStartTime() >= start);
    Assert.assertTrue(trace.getStartTime() <= end);
    TraceSegment segment = trace.getInitialTraceSegment();
    Assert.assertEquals(3, segment.getChildren().size());
    long relativeStart = segment.getRelativeStartTime();
    long relativeEnd = segment.getRelativeEndTime();
    for (TraceSegment current : segment.getChildren()) {
        Map<String, Object> info = current.getTracerAttributes();
        Assert.assertNull(info.get("async_context"));
        Assert.assertNotNull(info.get("exclusive_duration_millis"));
        Assert.assertEquals(0, current.getChildren().size());
        Assert.assertTrue(current.getMethodName().startsWith("default"));
        Assert.assertTrue(current.getName().startsWith("Custom/default"));
        Assert.assertTrue(current.getRelativeStartTime() >= relativeStart);
        Assert.assertTrue(current.getRelativeEndTime() <= relativeEnd);
        Assert.assertTrue(current.getRelativeStartTime() <= current.getRelativeEndTime());
        Assert.assertEquals("MyClass", current.getClassName());
        if (current.getName().equals("Custom/default3")) {
            Assert.assertEquals("hello", info.get("myatt"));
            Assert.assertEquals(99, info.get("myNumber"));
        }
    }
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) Tracer(com.newrelic.agent.tracers.Tracer) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) TraceSegment(com.newrelic.agent.introspec.TraceSegment) Test(org.junit.Test)

Example 50 with TracedMetricData

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

the class AkkaTest method testRoutedActorSend.

@Test
public void testRoutedActorSend() throws InterruptedException {
    ActorSystem system = ActorSystem.create("AkkaTestSystem");
    TestApp.sendRoutedMessageInTransaction(system);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    int finishedTransactionCount = introspector.getFinishedTransactionCount(5000);
    assertEquals(1, finishedTransactionCount);
    String transactionName = "OtherTransaction/Akka/Routing";
    Map<String, TracedMetricData> metricsForTransaction = introspector.getMetricsForTransaction(transactionName);
    assertTrue(metricsForTransaction.containsKey("Akka/receive/" + RoutingActor.class.getName()));
}
Also used : ActorSystem(akka.actor.ActorSystem) TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) Introspector(com.newrelic.agent.introspec.Introspector) RoutingActor(com.nr.instrumentation.akka22.test.actors.routing.RoutingActor) 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