Search in sources :

Example 51 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class ErrorServiceTest method errorCountMetrics.

@Test
public void errorCountMetrics() throws Exception {
    Map<String, Object> config = createConfig("java.lang.Exception");
    EventTestHelper.createServiceManager(config);
    MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMService();
    rpmService.setIsConnected(true);
    TransactionService txService = ServiceFactory.getTransactionService();
    Throwable error = new ArrayIndexOutOfBoundsException();
    TransactionData data = createTransactionData(true, 0, error, false);
    TransactionStats transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats("Errors/WebTransaction/Uri/dude").getCallCount());
    Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats(MetricNames.WEB_TRANSACTION_ERRORS_ALL).getCallCount());
    data = createTransactionData(true, 0, null, false);
    transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats("Errors/WebTransaction/Uri/dude").getCallCount());
    Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats(MetricNames.WEB_TRANSACTION_ERRORS_ALL).getCallCount());
    data = createTransactionData(false, 0, error, false);
    transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats("Errors/OtherTransaction/Custom/dude").getCallCount());
    Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats(MetricNames.OTHER_TRANSACTION_ERRORS_ALL).getCallCount());
    data = createTransactionData(false, 0, null, false);
    transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats("Errors/OtherTransaction/Custom/dude").getCallCount());
    Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats(MetricNames.WEB_TRANSACTION_ERRORS_ALL).getCallCount());
    StatsService spy = spy(new StatsServiceImpl());
    ((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
    ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
    StatsEngine statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
    List<TracedError> actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
    Assert.assertEquals(2, actualErrors.size());
    Assert.assertEquals(2, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
    spy = spy(new StatsServiceImpl());
    ((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
    statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
    actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
    Assert.assertEquals(0, actualErrors.size());
    Assert.assertEquals(0, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
    data = createTransactionData(true, 0, error, false);
    txService.transactionFinished(data, new TransactionStats());
    spy = spy(new StatsServiceImpl());
    ((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
    statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
    actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
    Assert.assertEquals(1, actualErrors.size());
    Assert.assertEquals(1, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
}
Also used : TransactionService(com.newrelic.agent.TransactionService) StatsService(com.newrelic.agent.stats.StatsService) StatsEngine(com.newrelic.agent.stats.StatsEngine) TransactionStats(com.newrelic.agent.stats.TransactionStats) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) TransactionData(com.newrelic.agent.TransactionData) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 52 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class TokenTimeoutTest method testTxnAttrTokenTimeout.

@Test
public void testTxnAttrTokenTimeout() throws InterruptedException {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    // Name the transaction so we can identify it in the listener below and create an event
    tx.setTransactionName(TransactionNamePriority.CUSTOM_HIGH, true, "TokenTimeout", "timeout");
    final List<TransactionEvent> events = new ArrayList<>();
    final CountDownLatch latch = new CountDownLatch(1);
    ServiceFactory.getServiceManager().getTransactionService().addTransactionListener(new TransactionListener() {

        @Override
        public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
            if (transactionData.getPriorityTransactionName().getName().equals("WebTransaction/TokenTimeout/timeout")) {
                events.add(ServiceFactory.getTransactionEventsService().createEvent(transactionData, transactionStats, transactionData.getBlameOrRootMetricName()));
                latch.countDown();
            }
        }
    });
    tx.getTransactionActivity().tracerStarted(rootTracer);
    // Let this timeout the transaction
    Token token = tx.getToken();
    rootTracer.finish(Opcodes.RETURN, 0);
    assertFalse(tx.isFinished());
    // Don't start the thread. The timeout is configured to 0 seconds.
    // Allow it to expire and then run the code that implements it.
    busyWait(1000);
    latch.await();
    assertTrue(tx.isFinished());
    assertFalse(events.isEmpty());
    assertEquals("WebTransaction/TokenTimeout/timeout", events.get(0).getName());
    assertEquals(TimeoutCause.TOKEN, events.get(0).getTimeoutCause());
}
Also used : TransactionListener(com.newrelic.agent.TransactionListener) ExtendedTransactionListener(com.newrelic.agent.ExtendedTransactionListener) TransactionEvent(com.newrelic.agent.service.analytics.TransactionEvent) TransactionStats(com.newrelic.agent.stats.TransactionStats) Transaction(com.newrelic.agent.Transaction) Tracer(com.newrelic.agent.tracers.Tracer) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Token(com.newrelic.agent.bridge.Token) TransactionData(com.newrelic.agent.TransactionData) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 53 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class DistributedTracingTest method testCrossApplicationTracingDisabled.

@Test
public void testCrossApplicationTracingDisabled() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("cross_application_disabled_test");
    TransactionService transactionService = ServiceFactory.getTransactionService();
    final CountDownLatch latch = new CountDownLatch(1);
    TransactionStatsListener listener = new TransactionStatsListener() {

        @Override
        public void dispatcherTransactionStatsFinished(TransactionData transactionData, TransactionStats transactionStats) {
            // Use this to ensure that the transaction fully finished and that it
            // didn't bail out early (transaction stats listeners are fired at the end of tx processing)
            latch.countDown();
        }
    };
    try {
        transactionService.addTransactionStatsListener(listener);
        noCreateOrAcceptPayload();
        // Wait up to 30 seconds for the transaction to finish, if it doesn't then it means we encountered an issue and it never finished
        latch.await(30, TimeUnit.SECONDS);
        SpanEventsService spanEventsService = ServiceFactory.getServiceManager().getSpanEventsService();
        String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
        SamplingPriorityQueue<SpanEvent> spanEventsPool = spanEventsService.getOrCreateDistributedSamplingReservoir(appName);
        assertNotNull(spanEventsPool);
        List<SpanEvent> spanEvents = spanEventsPool.asList();
        assertNotNull(spanEvents);
        assertEquals(1, spanEvents.size());
        spanEventsPool.clear();
        SpanEvent firstSpanEvent = Iterables.getFirst(spanEvents, null);
        assertNotNull(firstSpanEvent);
        String traceId = firstSpanEvent.getTraceId();
        for (SpanEvent event : spanEvents) {
            // Assert that all tracers have the same traceId
            assertEquals(traceId, event.getTraceId());
        }
        TransactionDataList transactionList = holder.getTransactionList();
        assertNotNull(transactionList);
        assertEquals(1, transactionList.size());
    } finally {
        transactionService.removeTransactionStatsListener(listener);
        holder.close();
    }
}
Also used : TransactionStatsListener(com.newrelic.agent.TransactionStatsListener) TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionStats(com.newrelic.agent.stats.TransactionStats) TransactionService(com.newrelic.agent.TransactionService) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) SpanEvent(com.newrelic.agent.model.SpanEvent) TransactionData(com.newrelic.agent.TransactionData) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 54 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class FlyweightTracerTest method test.

@Trace(dispatcher = true)
@Test
public void test() {
    int count = 100000;
    callManyTimes(count);
    Transaction transaction = Transaction.getTransaction();
    TransactionStats transactionStats = transaction.getTransactionActivity().getTransactionStats();
    ResponseTimeStats time = transactionStats.getScopedStats().getOrCreateResponseTimeStats("Java/test.newrelic.test.agent.FlyweightTracerTest/fastMethodDude");
    ResponseTimeStats dude = transactionStats.getUnscopedStats().getOrCreateResponseTimeStats("Dude");
    ResponseTimeStats man = transactionStats.getUnscopedStats().getOrCreateResponseTimeStats("Man");
    Assert.assertEquals(count, time.getCallCount());
    Assert.assertEquals(count, dude.getCallCount());
    Assert.assertEquals(count, man.getCallCount());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) TransactionStats(com.newrelic.agent.stats.TransactionStats) Transaction(com.newrelic.agent.Transaction) Trace(com.newrelic.api.agent.Trace) Test(org.junit.Test)

Example 55 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class JavaUtilLoggerTest method getLogMetricsCounts.

private Map<String, Integer> getLogMetricsCounts() {
    Transaction transaction = Transaction.getTransaction();
    TransactionStats transactionStats = transaction.getTransactionActivity().getTransactionStats();
    SimpleStatsEngine engine = transactionStats.getUnscopedStats();
    final Map<String, Integer> metrics = new HashMap<>();
    metrics.put("Logging/lines", engine.getStats("Logging/lines").getCallCount());
    metrics.put("Logging/lines/FINEST", engine.getStats("Logging/lines/FINEST").getCallCount());
    metrics.put("Logging/lines/FINER", engine.getStats("Logging/lines/FINER").getCallCount());
    metrics.put("Logging/lines/FINE", engine.getStats("Logging/lines/FINE").getCallCount());
    metrics.put("Logging/lines/CONFIG", engine.getStats("Logging/lines/CONFIG").getCallCount());
    metrics.put("Logging/lines/INFO", engine.getStats("Logging/lines/INFO").getCallCount());
    metrics.put("Logging/lines/WARNING", engine.getStats("Logging/lines/WARNING").getCallCount());
    metrics.put("Logging/lines/SEVERE", engine.getStats("Logging/lines/SEVERE").getCallCount());
    return metrics;
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Transaction(com.newrelic.agent.Transaction) HashMap(java.util.HashMap) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine)

Aggregations

TransactionStats (com.newrelic.agent.stats.TransactionStats)104 Test (org.junit.Test)90 TransactionData (com.newrelic.agent.TransactionData)40 EventTestHelper.generateTransactionData (com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData)15 Tracer (com.newrelic.agent.tracers.Tracer)15 HashMap (java.util.HashMap)14 SpanEvent (com.newrelic.agent.model.SpanEvent)13 TransactionService (com.newrelic.agent.TransactionService)12 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)11 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)11 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)11 ArrayList (java.util.ArrayList)11 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)10 Map (java.util.Map)9 Transaction (com.newrelic.agent.Transaction)8 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)8 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)7 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 JSONArray (org.json.simple.JSONArray)5