use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.
the class DatabaseTest method sqlException.
@Test
public void sqlException() throws Exception {
final String BAD_SQL = "this sql is no good!";
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
final Map<String, Object> params = new HashMap<>();
try {
new StubServlet("dude") {
private static final long serialVersionUID = 1L;
@Override
protected void run(HttpServletRequest request, HttpServletResponse response) throws Exception {
Connection connection = DatabaseHelper.getConnection();
Statement stmt = connection.createStatement();
try {
stmt.executeQuery(BAD_SQL);
} finally {
params.putAll(Transaction.getTransaction().getIntrinsicAttributes());
}
}
};
} catch (Exception e) {
}
Assert.assertEquals(2, txs.size());
TransactionData transactionData = txs.get(1);
Assert.assertEquals(500, transactionData.getResponseStatus());
Assert.assertEquals(BAD_SQL, params.get("sql"));
}
use of com.newrelic.agent.TransactionDataList 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.TransactionDataList in project newrelic-java-agent by newrelic.
the class ExpectedErrorsTest method expectedErrorNoTransaction.
@Test
public void expectedErrorNoTransaction() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("expected_error_test");
try {
try {
throwExceptionNoTransaction("something");
fail("The expected exception was not thrown");
} catch (Throwable t) {
}
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(0, transactionList.size());
StatsEngine statsEngine = holder.getStatsEngine();
assertEquals(0, statsEngine.getStats("Errors/all").getCallCount());
assertEquals(1, statsEngine.getStats("ErrorsExpected/all").getCallCount());
verifyExpectedErrorSupportabilityApiCalls(statsEngine, 0, 0, 1, 0);
verifyIgnoreErrorSupportabilityApiCalls(statsEngine, 0, 0, 0);
} finally {
holder.close();
}
}
use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.
the class ExpectedErrorsTest method expectedErrorWrongMessage.
@Test
public void expectedErrorWrongMessage() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("expected_error_bad_message_test");
try {
try {
throwException("pleasen be right");
fail("The expected exception was not thrown");
} catch (Throwable t) {
}
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(1, transactionList.size());
TransactionData td = transactionList.get(0);
assertEquals("OtherTransaction/Custom/test.newrelic.test.agent.ExpectedErrorsTest/throwException", td.getPriorityTransactionName().getName());
StatsEngine statsEngine = holder.getStatsEngine();
assertEquals(0, statsEngine.getStats("ErrorsExpected/all").getCallCount());
assertEquals(1, statsEngine.getStats("Errors/all").getCallCount());
verifyExpectedErrorSupportabilityApiCalls(statsEngine, 0, 0, 0, 1);
verifyIgnoreErrorSupportabilityApiCalls(statsEngine, 0, 1, 0);
} finally {
holder.close();
}
}
use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.
the class ExpectedErrorsTest method nonExpectedErrorNoTransaction.
@Test
public void nonExpectedErrorNoTransaction() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("non_expected_error_test");
try {
try {
throwExceptionNoTransaction("something");
fail("The expected exception was not thrown");
} catch (Throwable t) {
}
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(0, transactionList.size());
StatsEngine statsEngine = holder.getStatsEngine();
assertEquals(0, statsEngine.getStats("ErrorsExpected/all").getCallCount());
assertEquals(1, statsEngine.getStats("Errors/all").getCallCount());
verifyExpectedErrorSupportabilityApiCalls(statsEngine, 0, 0, 1, 0);
verifyIgnoreErrorSupportabilityApiCalls(statsEngine, 0, 0, 0);
} finally {
holder.close();
}
}
Aggregations