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