Search in sources :

Example 6 with TransactionStats

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());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) SpanEventsServiceImpl(com.newrelic.agent.service.analytics.SpanEventsServiceImpl) InetSocketAddress(java.net.InetSocketAddress) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) Connection(java.sql.Connection) DummyConnection(sql.DummyConnection) SpanEvent(com.newrelic.agent.model.SpanEvent) DummyResultSet(sql.DummyResultSet) Test(org.junit.Test)

Example 7 with TransactionStats

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);
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) SpanEventsServiceImpl(com.newrelic.agent.service.analytics.SpanEventsServiceImpl) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) SpanEvent(com.newrelic.agent.model.SpanEvent) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 8 with TransactionStats

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);
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) TransactionStats(com.newrelic.agent.stats.TransactionStats)

Example 9 with TransactionStats

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());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 10 with TransactionStats

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);
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) HashMap(java.util.HashMap) ConfigServiceImpl(com.newrelic.agent.config.ConfigServiceImpl) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Aggregations

TransactionStats (com.newrelic.agent.stats.TransactionStats)104 Test (org.junit.Test)90 TransactionData (com.newrelic.agent.TransactionData)40 EventTestHelper.generateTransactionData (com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData)15 Tracer (com.newrelic.agent.tracers.Tracer)15 HashMap (java.util.HashMap)14 SpanEvent (com.newrelic.agent.model.SpanEvent)13 TransactionService (com.newrelic.agent.TransactionService)12 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)11 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)11 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)11 ArrayList (java.util.ArrayList)11 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)10 Map (java.util.Map)9 Transaction (com.newrelic.agent.Transaction)8 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)8 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)7 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 JSONArray (org.json.simple.JSONArray)5