Search in sources :

Example 26 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class SegmentTest method testPsuedoAsync2.

/**
 * tracer(dispatcher) start
 * --tracedActivity start
 * --tracer2 start
 * --tracer2 end
 * --tracedActivity finish
 * tracer finish
 * <p>
 * Transaction must have two txas due to the creation of tracer2 between the tracedActivity start and finish
 * Segment tracer must correctly link to root tracer.
 */
@Test
public void testPsuedoAsync2() throws InterruptedException {
    Tracer root = makeTransaction();
    Assert.assertNotNull(root);
    Assert.assertNotNull(root.getTransactionActivity().getTransaction());
    Thread.sleep(1);
    final Segment segment = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Custom Psuedo Async2");
    Assert.assertNotNull(segment);
    ExitTracer child = AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
    child.finish(Opcodes.ARETURN, null);
    assertTrue(child.getParentTracedMethod() == root);
    Thread.sleep(1);
    // Need to check this before the segment ends
    Assert.assertSame("Segment must be child of root tracer", root, segment.getTracedMethod().getParentTracedMethod());
    segment.end();
    root.finish(Opcodes.ARETURN, null);
    assertTrue(root.getTransactionActivity().getTransaction().isFinished());
    assertEquals(2, root.getTransactionActivity().getTransaction().getCountOfRunningAndFinishedTransactionActivities());
    assertEquals(3, getNumTracers(root.getTransactionActivity().getTransaction()));
}
Also used : ExitTracer(com.newrelic.agent.bridge.ExitTracer) ExitTracer(com.newrelic.agent.bridge.ExitTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 27 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class SegmentTest method testCorrectParenting.

/**
 * Segments have their own txa since they're all ended async.
 */
@Test
public void testCorrectParenting() throws InterruptedException {
    Tracer root = makeTransaction();
    Assert.assertNotNull(root);
    Assert.assertNotNull(root.getTransactionActivity().getTransaction());
    {
        final Segment segmentUnderRoot = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Under Root");
        Assert.assertNotNull(segmentUnderRoot);
        Assert.assertSame("Segment has the wrong parent", root, segmentUnderRoot.getTracedMethod().getParentTracedMethod());
        segmentUnderRoot.end();
    }
    {
        ExitTracer child1 = AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild1", DefaultTracer.DEFAULT_TRACER_FLAGS);
        {
            final Segment underChild1 = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Under Child");
            Assert.assertNotNull(underChild1);
            Assert.assertSame("Segment has the wrong parent", child1, underChild1.getTracedMethod().getParentTracedMethod());
            underChild1.end();
        }
        {
            ExitTracer child2 = AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild2", DefaultTracer.DEFAULT_TRACER_FLAGS);
            {
                final Segment underChild2 = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Under Child 2");
                Assert.assertNotNull(underChild2);
                Assert.assertSame("Segment has the wrong parent", child2, underChild2.getTracedMethod().getParentTracedMethod());
                underChild2.end();
            }
            child2.finish(Opcodes.ARETURN, null);
        }
        child1.finish(Opcodes.ARETURN, null);
    }
    assertFalse(root.getTransactionActivity().getTransaction().isFinished());
    root.finish(Opcodes.ARETURN, null);
    assertTrue(root.getTransactionActivity().getTransaction().isFinished());
    // 4 txas: 1 for each of the 3 segments + 1 tracer
    assertEquals(4, root.getTransactionActivity().getTransaction().getCountOfRunningAndFinishedTransactionActivities());
    assertEquals(6, getNumTracers(root.getTransactionActivity().getTransaction()));
}
Also used : ExitTracer(com.newrelic.agent.bridge.ExitTracer) ExitTracer(com.newrelic.agent.bridge.ExitTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 28 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class SegmentTest method testMetricMigrationAsync.

@Test
public void testMetricMigrationAsync() throws InterruptedException {
    Tracer root = makeTransaction();
    Assert.assertNotNull(root);
    Assert.assertNotNull(root.getTransactionActivity().getTransaction());
    final Segment segment = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Custom Segment");
    segment.getTracedMethod().addRollupMetricName("rollupMetric");
    Thread finishThread = new Thread(new Runnable() {

        @Override
        public void run() {
            segment.getTracedMethod().addRollupMetricName("rollupMetric2");
            segment.end();
        }
    });
    finishThread.start();
    finishThread.join();
    root.finish(Opcodes.ARETURN, null);
    assertTrue(root.getTransactionActivity().getTransaction().isFinished());
    ResponseTimeStats rollupMetric = root.getTransactionActivity().getTransactionStats().getUnscopedStats().getOrCreateResponseTimeStats("rollupMetric");
    assertEquals(1, rollupMetric.getCallCount());
    ResponseTimeStats exclusiveRollupMetric = root.getTransactionActivity().getTransactionStats().getUnscopedStats().getOrCreateResponseTimeStats("rollupMetric2");
    assertEquals(1, exclusiveRollupMetric.getCallCount());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) ExitTracer(com.newrelic.agent.bridge.ExitTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 29 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class TransactionServiceTest method testDispatcherTransactionFinished.

@Test
public void testDispatcherTransactionFinished() {
    final AtomicReference<Transaction> finishedTransaction = new AtomicReference<>(null);
    final AtomicReference<Transaction> finishedTransactionExtended = new AtomicReference<>(null);
    ServiceFactory.getTransactionService().addTransactionListener(new ExtendedTransactionListener() {

        @Override
        public void dispatcherTransactionStarted(Transaction transaction) {
        }

        @Override
        public void dispatcherTransactionCancelled(Transaction transaction) {
        }

        @Override
        public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
            finishedTransactionExtended.set(transactionData.getTransaction());
        }
    });
    ServiceFactory.getTransactionService().addTransactionListener(new TransactionListener() {

        @Override
        public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
            finishedTransaction.set(transactionData.getTransaction());
        }
    });
    Tracer tracer = makeTransaction();
    tracer.finish(0, null);
    tracer.getParentTracer().finish(0, null);
    assertNotNull(tracer);
    assertNotNull(finishedTransaction.get());
    assertNotNull(finishedTransactionExtended.get());
    assertEquals(tracer.getTransactionActivity().getTransaction(), finishedTransaction.get());
    assertEquals(tracer.getTransactionActivity().getTransaction(), finishedTransactionExtended.get());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 30 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class TransactionStateImplTest method tracerGeneration_segmentClampInPlace_afterRoot.

@Test
public void tracerGeneration_segmentClampInPlace_afterRoot() throws Exception {
    Tracer rootTracer = createRootTracer();
    Transaction tx = Transaction.getTransaction();
    TransactionCounts transactionCounts = tx.getTransactionCounts();
    TracerFactory tracerFactory = Mockito.mock(TracerFactory.class, new Returns(rootTracer));
    tx.getTransactionState().getTracer(tx, tracerFactory, null, null, (Object[]) null);
    assertEquals(rootTracer, tx.getTransactionActivity().getRootTracer());
    transactionCounts.addTracers(3001);
    ClassMethodSignature sig = new ClassMethodSignature("com.test.Dude", "dude1", "()V");
    Tracer tracer = tx.getTransactionState().getTracer(tx, null, sig, null, simpleFlags);
    assertNotEquals(UltraLightTracer.class, tracer.getClass());
    assertEquals("Java/com.test.Dude/dude1", tracer.getTransactionSegmentName());
    Tracer sqlTracer = tx.getTransactionState().getSqlTracer(tx, null, sig, null, simpleFlags);
    assertEquals(UltraLightTracer.class, sqlTracer.getClass());
    assertEquals("Clamped/com.test.Dude/dude1", sqlTracer.getTransactionSegmentName());
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) UltraLightTracer(com.newrelic.agent.tracers.UltraLightTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) TransactionCounts(com.newrelic.agent.transaction.TransactionCounts) TracerFactory(com.newrelic.agent.tracers.TracerFactory) Test(org.junit.Test)

Aggregations

Tracer (com.newrelic.agent.tracers.Tracer)263 Test (org.junit.Test)195 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)104 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)99 Transaction (com.newrelic.agent.Transaction)86 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)54 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)41 ExitTracer (com.newrelic.agent.bridge.ExitTracer)39 TokenImpl (com.newrelic.agent.TokenImpl)35 StartAndThenLink (com.newrelic.agent.TransactionAsyncUtility.StartAndThenLink)31 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)25 TransactionData (com.newrelic.agent.TransactionData)24 HashMap (java.util.HashMap)24 SqlTracer (com.newrelic.agent.tracers.SqlTracer)20 ArrayList (java.util.ArrayList)19 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)17 TransactionStats (com.newrelic.agent.stats.TransactionStats)16 MockRPMService (com.newrelic.agent.MockRPMService)15 JSONArray (org.json.simple.JSONArray)15 JSONObject (org.json.simple.JSONObject)14