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