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