Search in sources :

Example 66 with TransactionStats

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

the class SegmentTest method testTxnAttrSegmentTimeout.

@Test(timeout = 30000)
public void testTxnAttrSegmentTimeout() throws InterruptedException {
    inlineExpirationService.setTimeout(0);
    try {
        Transaction.clearTransaction();
        Tracer rootTracer = makeTransaction();
        Transaction tx = rootTracer.getTransactionActivity().getTransaction();
        // Name the transaction so we can identify it in the listener below and create an event
        tx.setTransactionName(TransactionNamePriority.CUSTOM_HIGH, true, "SegmentTimeout", "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("OtherTransaction/SegmentTimeout/timeout")) {
                    events.add(ServiceFactory.getTransactionEventsService().createEvent(transactionData, transactionStats, transactionData.getBlameOrRootMetricName()));
                    latch.countDown();
                }
            }
        });
        tx.getTransactionActivity().tracerStarted(rootTracer);
        // Let this timeout the transaction
        com.newrelic.api.agent.Segment segment = TransactionApiImpl.INSTANCE.startSegment(null);
        rootTracer.finish(Opcodes.RETURN, 0);
        assertFalse(tx.isFinished());
        // Don't start the thread. The timeout is configured to 3 seconds.
        // Allow it to expire and then run the code that implements it.
        Thread.sleep(5000);
        latch.await();
        assertTrue(tx.isFinished());
        assertFalse(events.isEmpty());
        assertEquals("OtherTransaction/SegmentTimeout/timeout", events.get(0).getName());
        assertEquals(TimeoutCause.SEGMENT, events.get(0).getTimeoutCause());
    } finally {
        inlineExpirationService.clearTimeout();
    }
}
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) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) TransactionEvent(com.newrelic.agent.service.analytics.TransactionEvent) TransactionStats(com.newrelic.agent.stats.TransactionStats) Test(org.junit.Test)

Example 67 with TransactionStats

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

the class TransactionEventsServiceTest method testUserParametersDisabled.

@Test
public void testUserParametersDisabled() throws Exception {
    setup(true, false, TEST_RESERVOIR_SIZE);
    Map<String, Object> userParams = new LazyMapImpl<>();
    userParams.put("key1", "value1");
    userParams.put("key2", "value2");
    TransactionData transactionData = generateTransactionDataAndComplete(userParams, APP_NAME);
    TransactionStats transactionStats = new TransactionStats();
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(8, TimeUnit.MILLISECONDS);
    // populate the eventData map
    service.harvestEvents(APP_NAME);
    DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
    assertEquals(0, currentEventData.size());
    service.dispatcherTransactionFinished(transactionData, transactionStats);
    assertEquals(1, currentEventData.size());
    assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData.peek().getDuration(), 0);
    assertTrue(currentEventData.peek().getUserAttributesCopy().isEmpty());
    service.harvestEvents(APP_NAME);
    currentEventData = getEventData(APP_NAME);
    assertEquals(0, currentEventData.size());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) LazyMapImpl(com.newrelic.agent.LazyMapImpl) Test(org.junit.Test)

Example 68 with TransactionStats

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

the class TransactionEventsServiceTest method testSyntheticsBuffering1.

@Test
public void testSyntheticsBuffering1() throws Exception {
    setup(true, true, TEST_RESERVOIR_SIZE);
    this.rpmService.setSendAnalyticsEventsException(new HttpError("", HttpResponseCode.REQUEST_TIMEOUT, 0));
    TransactionData transactionData = generateSyntheticTransactionData();
    TransactionStats transactionStats = new TransactionStats();
    service.dispatcherTransactionFinished(transactionData, transactionStats);
    service.harvestEvents(APP_NAME);
    assertEquals(1, service.pendingSyntheticsHeaps.size());
    assertEquals(1, service.pendingSyntheticsHeaps.getFirst().size());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) HttpError(com.newrelic.agent.transport.HttpError) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 69 with TransactionStats

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

the class TransactionEventsServiceTest method distributedTraceIntrinicsAreAdded.

@Test
public void distributedTraceIntrinicsAreAdded() throws Exception {
    setup(true, true, TEST_RESERVOIR_SIZE);
    TransactionData transactionData = generateTransactionData(APP_NAME);
    when(mockDistributedTraceIntrinsics.buildDistributedTracingIntrinsics(any(TransactionData.class), eq(true))).thenReturn(Collections.<String, Object>singletonMap("dt-intrinsic", "here I am"));
    TransactionStats transactionStats = new TransactionStats();
    service.dispatcherTransactionFinished(transactionData, transactionStats);
    assertEquals(1, getEventData(APP_NAME).size());
    TransactionEvent result = getEventData(APP_NAME).asList().get(0);
    assertEquals(Collections.<String, Object>singletonMap("dt-intrinsic", "here I am"), result.getDistributedTraceIntrinsics());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 70 with TransactionStats

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

the class TransactionEventsServiceTest method testJSONStreaming.

@Test
public void testJSONStreaming() throws Exception {
    setup(true, true, TEST_RESERVOIR_SIZE);
    TransactionData transactionData = generateTransactionData(APP_NAME);
    TransactionStats transactionStatsEmpty = new TransactionStats();
    TransactionStats transactionStats = new TransactionStats();
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(1, TimeUnit.MILLISECONDS);
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.OTHER_TRANSACTION).recordResponseTime(2, TimeUnit.MILLISECONDS);
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.QUEUE_TIME).recordResponseTime(3, TimeUnit.MILLISECONDS);
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.EXTERNAL_ALL).recordResponseTime(4, TimeUnit.MILLISECONDS);
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(DatastoreMetrics.ALL).recordResponseTime(5, TimeUnit.MILLISECONDS);
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.GC_CUMULATIVE).recordResponseTime(6, TimeUnit.MILLISECONDS);
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.EXTERNAL_ALL).recordResponseTime(7, TimeUnit.MILLISECONDS);
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(DatastoreMetrics.ALL).recordResponseTime(8, TimeUnit.MILLISECONDS);
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(DatastoreMetrics.ALL).recordResponseTime(9, TimeUnit.MILLISECONDS);
    service.dispatcherTransactionFinished(transactionData, transactionStatsEmpty);
    service.dispatcherTransactionFinished(transactionData, transactionStats);
    DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
    TransactionEvent event = currentEventData.poll();
    Writer writer = new StringWriter();
    event.writeJSONString(writer);
    String json = writer.toString();
    assertNotNull(json);
    TransactionEvent eventFull = currentEventData.poll();
    Writer writerFull = new StringWriter();
    eventFull.writeJSONString(writerFull);
    String jsonFull = writerFull.toString();
    assertNotNull(jsonFull);
    assertNotEquals(json, jsonFull);
    assertTrue(jsonFull.contains("\"externalCallCount\":2.0"));
    assertTrue(jsonFull.contains("\"externalDuration\":0.011"));
    assertTrue(jsonFull.contains("\"databaseCallCount\":3.0"));
    assertTrue(jsonFull.contains("\"databaseDuration\":0.022"));
    assertTrue(json.length() < jsonFull.length());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) StringWriter(java.io.StringWriter) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) Writer(java.io.Writer) StringWriter(java.io.StringWriter) Test(org.junit.Test)

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