Search in sources :

Example 46 with Tracer

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

the class SegmentTest method testTracedActivityHoldsTransactionOpen.

/**
 * Unfinished tracedActivities should not allow the transaction to finish.
 */
@Test
public void testTracedActivityHoldsTransactionOpen() 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, Segment.UNNAMED_SEGMENT);
    Assert.assertNotNull(segment);
    Thread.sleep(1);
    final Segment segment2 = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, Segment.UNNAMED_SEGMENT);
    root.finish(Opcodes.ARETURN, null);
    Thread.sleep(1);
    assertFalse(root.getTransactionActivity().getTransaction().isFinished());
    Thread.sleep(1);
    // Need to check this before the segment ends
    Assert.assertSame("Segment must be child of root tracer", root, segment.getTracedMethod().getParentTracedMethod());
    Assert.assertSame("Segment2 must be child of root tracer", root, segment2.getTracedMethod().getParentTracedMethod());
    segment.end();
    assertFalse(root.getTransactionActivity().getTransaction().isFinished());
    Thread.sleep(1);
    segment2.end();
    Thread.sleep(1);
    assertTrue(root.getTransactionActivity().getTransaction().isFinished());
    assertEquals(3, root.getTransactionActivity().getTransaction().getCountOfRunningAndFinishedTransactionActivities());
    assertEquals(3, getNumTracers(root.getTransactionActivity().getTransaction()));
}
Also used : 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 47 with Tracer

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

the class SegmentTest method testAsyncWithoutTimeout.

/**
 * tracer(dispatcher) start
 * --tracedActivity start
 * (harvest)
 * --tracedActivity finish
 * tracer finish
 * <p>
 * Transaction should not timeout the segment
 */
@Test
public void testAsyncWithoutTimeout() throws InterruptedException {
    final long configTimeoutMillis = ServiceFactory.getConfigService().getDefaultAgentConfig().getValue("traced_activity_timeout", 10 * 60) * 1000;
    final Tracer root = makeTransaction();
    Assert.assertNotNull(root);
    Assert.assertNotNull(root.getTransactionActivity().getTransaction());
    Thread.sleep(1);
    final long startTs = System.currentTimeMillis();
    final Segment segment = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Custom Async Without Timeout");
    Assert.assertNotNull(segment);
    ServiceFactory.getTransactionService().processQueue();
    final long durationMs = System.currentTimeMillis() - startTs;
    root.finish(Opcodes.ARETURN, null);
    // this will almost always be true since the configTimeout is 3 seconds.
    if (durationMs < configTimeoutMillis) {
        // the TA was running less than the timeout when the harvest completed. Should not have been timed out.
        assertEquals(2, root.getTransactionActivity().getTransaction().getCountOfRunningAndFinishedTransactionActivities());
    } else {
        // the TA was running more than the timeout when the harvest completed. Could have been timed out correctly.
        System.err.println("Skipping timeout assert. duration " + durationMs + " exceeds timeout " + configTimeoutMillis);
    }
    Assert.assertSame("Segment must be child of root tracer", root, segment.getTracedMethod().getParentTracedMethod());
    // now let's finish
    segment.end();
    assertTrue(root.getTransactionActivity().getTransaction().isFinished());
    assertEquals(2, getNumTracers(root.getTransactionActivity().getTransaction()));
}
Also used : 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 48 with Tracer

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

the class TransactionAsyncEdgeCaseTest method testLinkSameThreadOneTracer.

@Test
public void testLinkSameThreadOneTracer() throws InterruptedException {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    TokenImpl token = (TokenImpl) tx.getToken();
    Transaction.linkTxOnThread(token);
    token.expire();
    rootTracer.finish(Opcodes.RETURN, 0);
    waitForTransaction();
    Assert.assertNotNull(data);
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, data.getTransactionActivities().size());
    Collection<Tracer> tracers = data.getTracers();
    Assert.assertEquals(1, tracers.size() + 1);
    Assert.assertEquals("RequestDispatcher", data.getRootTracer().getMetricName());
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) Test(org.junit.Test)

Example 49 with Tracer

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

the class TransactionAsyncEdgeCaseTest method testLinkAndExpireSameThreadTwoTracers.

@Test
public void testLinkAndExpireSameThreadTwoTracers() throws InterruptedException {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    TokenImpl token = (TokenImpl) tx.getToken();
    token.linkAndExpire();
    Tracer defaultTracer = TransactionAsyncUtility.createDefaultTracer("mymethod");
    tx.getTransactionActivity().tracerStarted(defaultTracer);
    defaultTracer.finish(Opcodes.RETURN, 0);
    rootTracer.finish(Opcodes.RETURN, 0);
    waitForTransaction();
    Assert.assertNotNull(data);
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, data.getTransactionActivities().size());
    Collection<Tracer> tracers = data.getTracers();
    Assert.assertEquals(2, tracers.size() + 1);
    Iterator<Tracer> it = tracers.iterator();
    while (it.hasNext()) {
        Tracer t = it.next();
        Assert.assertEquals("Custom/mymethod", t.getMetricName());
    }
    Assert.assertEquals("RequestDispatcher", data.getRootTracer().getMetricName());
    Map<String, StatsBase> metrics = stats.getScopedStats().getStatsMap();
    ResponseTimeStatsImpl sb = (ResponseTimeStatsImpl) metrics.get("Custom/mymethod");
    Assert.assertEquals(1, sb.getCallCount());
    sb = (ResponseTimeStatsImpl) metrics.get("RequestDispatcher");
    Assert.assertEquals(1, sb.getCallCount());
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) StatsBase(com.newrelic.agent.stats.StatsBase) ResponseTimeStatsImpl(com.newrelic.agent.stats.ResponseTimeStatsImpl) Test(org.junit.Test)

Example 50 with Tracer

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

the class TransactionAsyncEdgeCaseTest method testLinkAndExpireSameThreadOneTracer.

@Test
public void testLinkAndExpireSameThreadOneTracer() throws InterruptedException {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    TokenImpl token = (TokenImpl) tx.getToken();
    token.linkAndExpire();
    rootTracer.finish(Opcodes.RETURN, 0);
    waitForTransaction();
    Assert.assertNotNull(data);
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, data.getTransactionActivities().size());
    Collection<Tracer> tracers = data.getTracers();
    Assert.assertEquals(1, tracers.size() + 1);
    Assert.assertEquals("RequestDispatcher", data.getRootTracer().getMetricName());
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) 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