use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DefaultSqlTracerTest method testSpanEventDatastoreTruncation.
@Test
public void testSpanEventDatastoreTruncation() throws SQLException {
final Connection connection = mock(Connection.class);
DatastoreInstanceDetection.detectConnectionAddress();
DatastoreInstanceDetection.associateAddress(connection, new InetSocketAddress("dbserver.nerd.us", 9945));
DatastoreInstanceDetection.stopDetectingConnectionAddress();
String longQueryString = "SELECT price, name FROM BOOKS WHERE name = " + Strings.repeat("a", 4000);
DefaultSqlTracer tracer = newInstanceDBTracer(longQueryString, connection, "MySQL", "mysql");
tracer.finish(Opcodes.ARETURN, new DummyResultSet());
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(tracer.getTransaction(), 1024), new TransactionStats());
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
List<SpanEvent> spanEvents = eventPool.asList();
assertNotNull(spanEvents);
assertEquals(1, spanEvents.size());
SpanEvent spanEvent = Iterables.getFirst(spanEvents, null);
assertNotNull(spanEvent);
assertEquals("datastore", spanEvent.getIntrinsics().get("category"));
assertEquals("MySQL", spanEvent.getIntrinsics().get("component"));
assertEquals("dbserver.nerd.us", spanEvent.getIntrinsics().get("peer.hostname"));
assertEquals("dbserver.nerd.us:9945", spanEvent.getIntrinsics().get("peer.address"));
assertEquals(2000, spanEvent.getIntrinsics().get("db.statement").toString().length());
assertTrue(spanEvent.getIntrinsics().get("db.statement").toString().endsWith("a..."));
assertEquals("books", spanEvent.getIntrinsics().get("db.collection"));
assertEquals("client", spanEvent.getIntrinsics().get("span.kind"));
assertEquals("Datastore/statement/MySQL/books/select", spanEvent.getName());
assertNotNull(spanEvent.getTraceId());
assertNotNull(spanEvent.getGuid());
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testSpanEvent.
@Test
public void testSpanEvent() {
DefaultTracer tracer = prepareTracer();
tracer.finish(0, null);
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(tracer.getTransaction(), 1024), new TransactionStats());
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
List<SpanEvent> spanEvents = eventPool.asList();
assertNotNull(spanEvents);
assertEquals(1, spanEvents.size());
SpanEvent spanEvent = Iterables.getFirst(spanEvents, null);
assertNotNull(spanEvent);
assertNull(spanEvent.getParentId());
assertEquals(tracer.getGuid(), spanEvent.getGuid());
assertEquals(tracer.getTransaction().getGuid(), spanEvent.getTransactionId());
assertEquals("Java/class/method", spanEvent.getName());
assertEquals(true, spanEvent.getIntrinsics().get("nr.entryPoint"));
assertEquals((float) tracer.getDurationInMilliseconds() / TimeConversion.MILLISECONDS_PER_SECOND, spanEvent.getDuration(), 0.001f);
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method checkInstanceMetric.
/**
* @param host Host to report.
* @param port Port to report.
* @param expectedHost expected host in instance metric.
* @param expectedInstanceID expected identifier in instance metric.
*/
public void checkInstanceMetric(String product, String host, Integer port, String expectedHost, String expectedInstanceID) {
DefaultTracer tracer = prepareTracer();
final TransactionStats stats = tracer.getTransactionActivity().getTransactionStats();
tracer.reportAsExternal(DatastoreParameters.product(product).collection("MyCollection").operation("operation").instance(host, port).build());
tracer.finish(0, null);
ResponseTimeStats responseTimeStats = stats.getUnscopedStats().getOrCreateResponseTimeStats(String.format("Datastore/instance/DB/%s/%s", expectedHost, expectedInstanceID));
assertEquals(responseTimeStats.getCallCount(), 1);
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method test.
@Test
public void test() throws Exception {
setup(true, true, TEST_RESERVOIR_SIZE);
TransactionData transactionData = generateTransactionData(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);
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 testDifferentAppNamesOneDisabledMiddle.
@Test
public void testDifferentAppNamesOneDisabledMiddle() throws Exception {
setup(true, true, TEST_RESERVOIR_SIZE);
// default app name
TransactionData transactionData = generateTransactionData(APP_NAME);
TransactionStats transactionStats = new TransactionStats();
transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(8, TimeUnit.MILLISECONDS);
// second app name
TransactionData transactionData2 = generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), APP_NAME_2);
TransactionStats transactionStats2 = new TransactionStats();
transactionStats2.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(9, TimeUnit.MILLISECONDS);
// third app name
String appName3 = "thirdAppName";
TransactionData transactionData3 = generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), appName3);
TransactionStats transactionStats3 = new TransactionStats();
transactionStats3.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(10, TimeUnit.MILLISECONDS);
// populate the eventData map
service.harvestEvents(APP_NAME);
// populate the eventData map
service.harvestEvents(APP_NAME_2);
// populate the eventData map
service.harvestEvents(appName3);
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData2 = getEventData(APP_NAME_2);
assertEquals(0, currentEventData2.size());
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData3 = getEventData(appName3);
assertEquals(0, currentEventData3.size());
service.dispatcherTransactionFinished(transactionData, transactionStats);
service.dispatcherTransactionFinished(transactionData2, transactionStats2);
service.dispatcherTransactionFinished(transactionData3, transactionStats3);
assertEquals(1, currentEventData.size());
assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData.peek().getDuration(), 0);
assertEquals(1, currentEventData2.size());
assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData2.peek().getDuration(), 0);
assertEquals(1, currentEventData3.size());
assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData3.peek().getDuration(), 0);
// server side says app name 2 disabled
Map<String, Object> data = new HashMap<>();
data.put("collect_analytics_events", Boolean.FALSE);
((ConfigServiceImpl) configService).connected(rpmServiceAppName2, data);
// second time with second name
transactionData2 = generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), APP_NAME_2);
transactionStats2 = new TransactionStats();
transactionStats2.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(9, TimeUnit.MILLISECONDS);
service.dispatcherTransactionFinished(transactionData2, transactionStats2);
currentEventData2 = getEventData(APP_NAME_2);
// since the second app has been disabled - this should be false
assertNull(currentEventData2);
}
Aggregations