use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class SpanParentTest method testCrossProcessOnly.
@Test
public void testCrossProcessOnly() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("cross_process_only_test");
executeCrossProcessOnlyTest();
try {
TransactionDataList transactionList = holder.getTransactionList();
assertEquals(2, transactionList.size());
TransactionData tx1 = transactionList.get(0);
TransactionData tx2 = transactionList.get(1);
Collection<Tracer> tracers1 = tx1.getTracers();
// Only a "rootTracer" on this transaction (root tracer is not in this list)
assertEquals(0, tracers1.size());
Collection<Tracer> tracers2 = tx2.getTracers();
// 1 "rootTracer" (not in this list) + 2 non-external/datastore tracers + 2 external datastore tracers
assertEquals(4, tracers2.size());
SpanEventsService spanEventsService = ServiceFactory.getServiceManager().getSpanEventsService();
String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
SamplingPriorityQueue<SpanEvent> spanEventsPool = spanEventsService.getOrCreateDistributedSamplingReservoir(appName);
assertNotNull(spanEventsPool);
List<SpanEvent> spanEvents = spanEventsPool.asList();
spanEventsPool.clear();
assertNotNull(spanEvents);
assertEquals(2, spanEvents.size());
SpanEvent externalSpanEvent = null;
SpanEvent datastoreSpanEvent = null;
for (SpanEvent spanEvent : spanEvents) {
if (spanEvent.getCategory() == SpanCategory.http) {
externalSpanEvent = spanEvent;
} else if (spanEvent.getCategory() == SpanCategory.datastore) {
datastoreSpanEvent = spanEvent;
}
}
assertNotNull(externalSpanEvent);
assertNotNull(datastoreSpanEvent);
// For right now, we are putting cross-process only mode on ice. Poor orphan spans :(
assertNull(externalSpanEvent.getParentId());
assertNull(datastoreSpanEvent.getParentId());
} finally {
holder.close();
}
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class PreparedStatementSqlTest method sql.
@Test
public void sql() throws Exception {
final String originalSql = "select * from test where name = ?";
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
try {
new StubServlet("dude") {
private static final long serialVersionUID = 1L;
@Override
protected void run(HttpServletRequest request, HttpServletResponse response) throws Exception {
Connection connection = DatabaseHelper.getConnection();
PreparedStatement statement = connection.prepareStatement(originalSql);
statement.setString(1, "test");
statement.executeQuery();
}
};
} catch (Exception e) {
// ignore
}
Assert.assertEquals(2, txs.size());
TransactionData transactionData = txs.get(1);
String actualSql = null;
for (Tracer tracer : AgentHelper.getTracers(transactionData.getRootTracer())) {
if (tracer instanceof SqlTracer) {
actualSql = ((SqlTracer) tracer).getSql().toString();
}
}
Assert.assertNotNull(actualSql);
Assert.assertEquals("select * from test where name = 'test'", actualSql);
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class KafkaTest method produceConsumeTest.
@Test
public void produceConsumeTest() throws Exception {
EnvironmentHolderSettingsGenerator envHolderSettings = new EnvironmentHolderSettingsGenerator(CONFIG_FILE, "all_enabled_test", CLASS_LOADER);
EnvironmentHolder holder = new EnvironmentHolder(envHolderSettings);
holder.setupEnvironment();
kafkaUnitRule.getKafkaUnit().createTopic(testTopic, 1);
final KafkaConsumer<String, String> consumer = setupConsumer();
final CountDownLatch latch = new CountDownLatch(1);
final ConcurrentLinkedQueue<TransactionData> finishedTransactions = new ConcurrentLinkedQueue<>();
TransactionListener transactionListener = new TransactionListener() {
@Override
public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
finishedTransactions.add(transactionData);
latch.countDown();
}
};
ServiceFactory.getTransactionService().addTransactionListener(transactionListener);
try {
produceMessage();
final Future<?> submit = executorService.submit(new Runnable() {
@Override
public void run() {
consumeMessage(consumer);
}
});
submit.get(30, TimeUnit.SECONDS);
latch.await(30, TimeUnit.SECONDS);
Assert.assertEquals(2, finishedTransactions.size());
// Wait for the metrics reporter
Thread.sleep(1000);
// Assert on the kafka metrics that we're expecting
StatsEngine statsEngine = ServiceFactory.getStatsService().getStatsEngineForHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName());
Stats messagesConsumed = statsEngine.getStats("MessageBroker/Kafka/Internal/consumer-fetch-manager-metrics/records-consumed-rate");
Assert.assertNotNull(messagesConsumed);
Assert.assertTrue(messagesConsumed.getCallCount() > 1);
Assert.assertTrue(messagesConsumed.getTotal() > 0);
Stats bytesConsumed = statsEngine.getStats("MessageBroker/Kafka/Internal/consumer-metrics/incoming-byte-rate");
Assert.assertNotNull(bytesConsumed);
Assert.assertTrue(bytesConsumed.getCallCount() > 1);
Assert.assertTrue(bytesConsumed.getTotal() > 0);
Stats rebalanceAssignedPartition = statsEngine.getStats("MessageBroker/Kafka/Rebalance/Assigned/" + testTopic + "/0");
Assert.assertNotNull(rebalanceAssignedPartition);
Assert.assertEquals(1, rebalanceAssignedPartition.getCallCount());
Stats serializationByTopic = statsEngine.getStats("MessageBroker/Kafka/Serialization/TestTopic");
Assert.assertNotNull(serializationByTopic);
// One for the key, one for the value
Assert.assertEquals(2, serializationByTopic.getCallCount());
Assert.assertTrue(serializationByTopic.getTotal() > 1);
Stats deserializationByTopic = statsEngine.getStats("MessageBroker/Kafka/Deserialization/TestTopic");
Assert.assertNotNull(deserializationByTopic);
// One for the key, one for the value
Assert.assertEquals(2, deserializationByTopic.getCallCount());
Assert.assertTrue(deserializationByTopic.getTotal() > 1);
// external reporting test
TransactionData prodTxn = finishedTransactions.poll();
Collection<Tracer> tracers = prodTxn.getTracers();
Iterator<Tracer> iterator = tracers.iterator();
Assert.assertTrue(iterator.hasNext());
Tracer tracer = iterator.next();
Assert.assertEquals("MessageBroker/Kafka/Topic/Produce/Named/TestTopic", tracer.getMetricName());
TransactionData conTxn = finishedTransactions.poll();
Tracer rootTracer = conTxn.getRootTracer();
Assert.assertEquals("MessageBroker/Kafka/Topic/Consume/Named/TestTopic", rootTracer.getMetricName());
Assert.assertNotNull(conTxn.getInboundDistributedTracePayload());
} finally {
ServiceFactory.getTransactionService().removeTransactionListener(transactionListener);
consumer.close();
}
}
use of com.newrelic.agent.TransactionData 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.TransactionData 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());
}
Aggregations