Search in sources :

Example 21 with TracedMetricData

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

the class TransactionTraceTest method testOneTracerInTransactionWithDepthChildren.

@Test
public void testOneTracerInTransactionWithDepthChildren() {
    // 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);
    Tracer child2 = IntrospectorImplTest.createDefaultTracer("default2");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child2);
    Tracer child3 = IntrospectorImplTest.createDefaultTracer("default3");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child3);
    child3.setAgentAttribute("myatt", "hello");
    child3.setAgentAttribute("myNumber", 99);
    child3.finish(Opcodes.RETURN, 0);
    child2.finish(Opcodes.RETURN, 0);
    child1.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(1, segment.getChildren().size());
    TraceSegment seg = segment.getChildren().get(0);
    long relativeStart = segment.getRelativeStartTime();
    long relativeEnd = segment.getRelativeEndTime();
    int count = 0;
    while (seg != null) {
        count++;
        Assert.assertTrue(seg.getRelativeStartTime() >= relativeStart);
        Assert.assertTrue(seg.getRelativeEndTime() <= relativeEnd);
        Assert.assertTrue(seg.getRelativeStartTime() <= seg.getRelativeEndTime());
        relativeStart = seg.getRelativeStartTime();
        relativeEnd = seg.getRelativeEndTime();
        Map<String, Object> info = seg.getTracerAttributes();
        Assert.assertNull(info.get("async_context"));
        Assert.assertNotNull(info.get("exclusive_duration_millis"));
        Assert.assertTrue(seg.getMethodName().startsWith("default"));
        Assert.assertTrue(seg.getName().startsWith("Custom/default"));
        Assert.assertEquals("MyClass", seg.getClassName());
        if (seg.getName().equals("Custom/default3")) {
            Assert.assertEquals("hello", info.get("myatt"));
            Assert.assertEquals(99, info.get("myNumber"));
            Assert.assertEquals(0, seg.getChildren().size());
            seg = null;
        } else {
            Assert.assertEquals(1, seg.getChildren().size());
            seg = seg.getChildren().get(0);
        }
    }
    Assert.assertEquals(3, count);
}
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 22 with TracedMetricData

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

the class AkkaTest method testSend.

@Test
public void testSend() throws InterruptedException {
    ActorSystem system = ActorSystem.create("AkkaTestSystem");
    TestApp.sendMessageInTransaction(system);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    int finishedTransactionCount = introspector.getFinishedTransactionCount(5000);
    assertEquals(1, finishedTransactionCount);
    String transactionName = "OtherTransaction/AkkaForward/Forward";
    Map<String, TracedMetricData> metricsForTransaction = introspector.getMetricsForTransaction(transactionName);
    assertTrue(metricsForTransaction.containsKey("Akka/forward/forwardActor"));
    assertTrue(metricsForTransaction.containsKey("Akka/receive/" + ForwardActor.class.getName()));
}
Also used : ActorSystem(akka.actor.ActorSystem) ForwardActor(com.nr.instrumentation.akka22.test.actors.forwarding.ForwardActor) TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) Introspector(com.newrelic.agent.introspec.Introspector) Test(org.junit.Test)

Example 23 with TracedMetricData

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

the class AkkaTest method testBroadcast.

@Test
public void testBroadcast() throws InterruptedException {
    ActorSystem system = ActorSystem.create("AkkaTestSystem");
    TestApp.broadcastInTransaction(system);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    int finishedTransactionCount = introspector.getFinishedTransactionCount(5000);
    assertEquals(1, finishedTransactionCount);
    String transactionName = "OtherTransaction/Akka/Broadcast";
    Map<String, TracedMetricData> metricsForTransaction = introspector.getMetricsForTransaction(transactionName);
    assertTrue(metricsForTransaction.containsKey("Akka/receive/" + ActorA.class.getName()));
    assertTrue(metricsForTransaction.containsKey("Akka/receive/" + ActorB.class.getName()));
    assertTrue(metricsForTransaction.containsKey("Akka/receive/" + ActorC.class.getName()));
    Map<String, TracedMetricData> unscopedMetrics = introspector.getUnscopedMetrics();
    assertTrue(unscopedMetrics.containsKey("ActorA"));
    assertTrue(unscopedMetrics.containsKey("ActorB"));
    assertTrue(unscopedMetrics.containsKey("ActorC"));
}
Also used : ActorSystem(akka.actor.ActorSystem) TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) ActorA(com.nr.instrumentation.akka22.test.actors.broadcasting.ActorA) Introspector(com.newrelic.agent.introspec.Introspector) ActorB(com.nr.instrumentation.akka22.test.actors.broadcasting.ActorB) ActorC(com.nr.instrumentation.akka22.test.actors.broadcasting.ActorC) Test(org.junit.Test)

Example 24 with TracedMetricData

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

the class AkkaTest method testBroadcastStress.

@Test
public void testBroadcastStress() throws InterruptedException {
    /**
     * @formatter:off
     *
     * This test tries to cover the following case:
     *
     * Suppose System broadcasts a message to A and B. B forwards the same message to C.
     *
     *             System
     *            /      \
     *          A         B @Trace(dispatcher = true)
     *                    |
     *                    C
     *
     * A possible execution of this can be as follows:
     *
     *  A is busy, and does not read the message.
     *  B starts the transaction, and forwards message to C
     *  A wakes up, and reads message.
     *  C reads message.
     *
     *  We want to ensure that A never links to B.
     *
     *  To increase the likelihood of running into the execution above, we have actor A forward the same message to itself several times.
     *  We do the same thing for actor C.
     */
    ActorSystem system = ActorSystem.create("AkkaTestSystem");
    TestApp.broadcastStress(system);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    int finishedTransactionCount = introspector.getFinishedTransactionCount(5000);
    assertEquals(1, finishedTransactionCount);
    assertTrue(introspector.getTransactionNames().contains("OtherTransaction/Akka/ParentActor"));
    Map<String, TracedMetricData> unscopedMetrics = introspector.getUnscopedMetrics();
    assertFalse(unscopedMetrics.containsKey(ActorNoTxnBranch.ROLLUP_NAME));
}
Also used : ActorSystem(akka.actor.ActorSystem) TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) Introspector(com.newrelic.agent.introspec.Introspector) Test(org.junit.Test)

Example 25 with TracedMetricData

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

the class AkkaTest method testRoutedActorToRouteeSend.

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