Search in sources :

Example 1 with TransactionStatsListener

use of com.newrelic.agent.TransactionStatsListener 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)

Aggregations

TransactionData (com.newrelic.agent.TransactionData)1 TransactionDataList (com.newrelic.agent.TransactionDataList)1 TransactionService (com.newrelic.agent.TransactionService)1 TransactionStatsListener (com.newrelic.agent.TransactionStatsListener)1 SpanEvent (com.newrelic.agent.model.SpanEvent)1 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1