Search in sources :

Example 41 with Tracer

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

the class TransactionTest method testTracerLimit2.

@SuppressWarnings("unchecked")
@Test
public void testTracerLimit2() throws Exception {
    Map<String, Object> config = createConfigMap();
    Map<String, Object> ttmap = (Map) config.get(AgentConfigImpl.TRANSACTION_TRACER);
    ttmap.put("segment_limit", 3);
    createServiceManager(config);
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
    tx.getTransactionActivity().tracerStarted(rootTracer);
    DefaultTracer t1 = createBasicTracer("one");
    tx.getTransactionActivity().tracerStarted(t1);
    tx.getTransactionActivity().tracerFinished(t1, 0);
    DefaultTracer t2 = createBasicTracer("two");
    tx.getTransactionActivity().tracerStarted(t2);
    tx.getTransactionActivity().tracerFinished(t2, 0);
    DefaultTracer t3 = createBasicTracer("three");
    tx.getTransactionActivity().tracerStarted(t3);
    tx.getTransactionActivity().tracerFinished(t3, 0);
    DefaultTracer t4 = createBasicTracer("four");
    tx.getTransactionActivity().tracerStarted(t4);
    tx.getTransactionActivity().tracerFinished(t4, 0);
    DefaultTracer t5 = createBasicTracer("five");
    tx.getTransactionActivity().tracerStarted(t5);
    tx.getTransactionActivity().tracerFinished(t5, 0);
    finishTransaction(tx, rootTracer);
    Set<TransactionActivity> done = tx.getFinishedChildren();
    assertEquals(1, done.size());
    TransactionActivity txa = done.iterator().next();
    List<Tracer> tracers = txa.getTracers();
    assertEquals(3, tracers.size());
    assertTrue(tracers.contains(t1));
    assertTrue(tracers.contains(t2));
    assertTrue(tracers.contains(t3));
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) ImmutableMap(com.google.common.collect.ImmutableMap) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 42 with Tracer

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

the class TransactionTest method noticeThenSetAsAPIUsesCurrentSpan.

@Test
public void noticeThenSetAsAPIUsesCurrentSpan() throws Exception {
    createServiceManager(Collections.<String, Object>emptyMap());
    Transaction.clearTransaction();
    Tracer dispatcherTracer = createDispatcherTracer(true);
    Transaction tx = dispatcherTracer.getTransactionActivity().getTransaction();
    tx.getTransactionActivity().tracerStarted(dispatcherTracer);
    Throwable exc = new Throwable();
    tx.noticeTracerException(exc, "span id 1");
    tx.noticeTracerException(exc, "span id 2");
    tx.setThrowable(exc, TransactionErrorPriority.API, false);
    assertEquals(dispatcherTracer.getGuid(), tx.getThrowable().spanId);
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 43 with Tracer

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

the class TransactionTest method testSampleFlag.

@Test
public void testSampleFlag() throws Exception {
    Map<String, Object> configMap = createNRDTConfigMap(false);
    createServiceManager(configMap);
    serviceManager.setDistributedTraceService(mockDistributedTraceService);
    Transaction.clearTransaction();
    Tracer dispatcherTracer = createDispatcherTracer(true);
    Transaction transaction = dispatcherTracer.getTransactionActivity().getTransaction();
    transaction.getTransactionActivity().tracerStarted(dispatcherTracer);
    String inboundPayload = "{" + "  \"v\": [0,2]," + "  \"d\": {" + "    \"ty\": \"Mobile\"," + "    \"ac\": \"9123\"," + "    \"tk\": \"67890\"," + "    \"ap\": \"51424\"" + "    \"id\": \"27856f70d3d314b7\"," + "    \"tr\": \"3221bf09aa0bcf0d\"," + "    \"pr\": 0.0002," + "    \"ti\": 1482959525577," + "  }" + "}";
    transaction.acceptDistributedTracePayload(inboundPayload);
    dispatcherTracer.finish(Opcodes.ARETURN, null);
    assertEquals(0.0002f, transaction.getPriority(), 0.0f);
    Transaction.clearTransaction();
    dispatcherTracer = createDispatcherTracer(true);
    transaction = dispatcherTracer.getTransactionActivity().getTransaction();
    transaction.getTransactionActivity().tracerStarted(dispatcherTracer);
    inboundPayload = "{" + "  \"v\": [0,2]," + "  \"d\": {" + "    \"ty\": \"Mobile\"," + "    \"ac\": \"9123\"," + "    \"tk\": \"67890\"," + "    \"ap\": \"51424\"" + "    \"id\": \"27856f70d3d314b7\"," + "    \"tr\": \"3221bf09aa0bcf0d\"," + "    \"pr\": 1.348272," + "    \"ti\": 1482959525577" + "  }" + "}";
    transaction.acceptDistributedTracePayload(inboundPayload);
    dispatcherTracer.finish(Opcodes.ARETURN, null);
    assertTrue(DistributedTraceUtil.isSampledPriority(transaction.getPriority()));
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 44 with Tracer

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

the class TransactionTest method testSupportabilityCreateBeforeAccept.

@Test
public void testSupportabilityCreateBeforeAccept() throws Exception {
    Map<String, Object> configMap = createNRDTConfigMap(false);
    createServiceManager(configMap);
    final CountDownLatch latch = new CountDownLatch(1);
    final SimpleStatsEngine unscopedStats = new SimpleStatsEngine();
    ServiceFactory.getTransactionService().addTransactionListener(new TransactionListener() {

        @Override
        public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
            if (transactionData.getPriorityTransactionName().getName().equals("WebTransaction/Test/createBeforeAcceptTxn")) {
                unscopedStats.mergeStats(transactionStats.getUnscopedStats());
                latch.countDown();
            }
        }
    });
    Transaction.clearTransaction();
    Tracer dispatcherTracer = createDispatcherTracer(true);
    Transaction transaction = dispatcherTracer.getTransactionActivity().getTransaction();
    transaction.getTransactionActivity().tracerStarted(dispatcherTracer);
    transaction.setTransactionName(com.newrelic.api.agent.TransactionNamePriority.CUSTOM_HIGH, true, "Test", "createBeforeAcceptTxn");
    transaction.createDistributedTracePayload("spanId31238ou");
    String inboundPayload = "{" + "  \"v\": [0,2]," + "  \"d\": {" + "    \"ty\": \"Mobile\"," + "    \"ac\": \"9123\"," + "    \"tk\": \"67890\"," + "    \"ap\": \"51424\"" + "    \"id\": \"27856f70d3d314b7\"," + "    \"tr\": \"3221bf09aa0bcf0d\"," + "    \"pr\": 0.00001," + "    \"ti\": 1482959525577" + "  }" + "}";
    transaction.acceptDistributedTracePayload(inboundPayload);
    dispatcherTracer.finish(Opcodes.ARETURN, null);
    latch.await();
    assertTrue(1 <= transaction.getTransactionActivity().getTransactionStats().getUnscopedStats().getStats(MetricNames.SUPPORTABILITY_ACCEPT_PAYLOAD_CREATE_BEFORE_ACCEPT).getCallCount());
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 45 with Tracer

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

the class SegmentTest method makeTransaction.

/**
 * Creates a transaction with one tracer and returns the root tracer (unfinished).
 */
private static Tracer makeTransaction() {
    Transaction tx = Transaction.getTransaction(true);
    TransactionActivity txa = TransactionActivity.get();
    Assert.assertNotNull(txa);
    Tracer root = new OtherRootTracer(tx, new ClassMethodSignature("com.newrelic.agent.SegmentTest", "makeTransaction", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
    txa.tracerStarted(root);
    tx.setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, true, "FOO", "BAR", "BAZ");
    return root;
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) ExitTracer(com.newrelic.agent.bridge.ExitTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

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