Search in sources :

Example 16 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class TransactionEventsServiceTest method testDifferentAppNamesOneDisabled.

@Test
public void testDifferentAppNamesOneDisabled() throws Exception {
    setup(true, true, TEST_RESERVOIR_SIZE);
    // 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);
    // 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";
    rpmServiceManager.getOrCreateRPMService(appName3);
    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);
    currentEventData2 = getEventData(APP_NAME_2);
    assertNull(currentEventData2);
    assertEquals(1, currentEventData3.size());
    assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData3.peek().getDuration(), 0);
    service.harvestEvents(APP_NAME);
    currentEventData = getEventData(APP_NAME);
    assertEquals(0, currentEventData.size());
    service.harvestEvents(appName3);
    currentEventData3 = getEventData(appName3);
    assertEquals(0, currentEventData3.size());
}
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)

Example 17 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class DefaultTracerTest method testNoParametersInUri.

@Test
public void testNoParametersInUri() {
    DefaultTracer tracer = prepareTracer();
    TransactionStats stats = tracer.getTransactionActivity().getTransactionStats();
    String uri = "http://myhost:1234/Parameters";
    String queryParams = "?data=confidential";
    tracer.reportAsExternal(GenericParameters.library("MyLibrary").uri(URI.create(uri + queryParams)).procedure("other").build());
    tracer.recordMetrics(stats);
    assertEquals(uri, tracer.getTransactionSegmentUri());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Test(org.junit.Test)

Example 18 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class DefaultTracerTest method testGenericParametersNoHost.

@Test
public void testGenericParametersNoHost() {
    DefaultTracer tracer = prepareTracer();
    TransactionStats stats = tracer.getTransactionActivity().getTransactionStats();
    URI uriWithNoHost = URI.create("../icons/logo.gif");
    tracer.reportAsExternal(HttpParameters.library("library").uri(uriWithNoHost).procedure("procedure").noInboundHeaders().build());
    tracer.recordMetrics(stats);
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) URI(java.net.URI) Test(org.junit.Test)

Example 19 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class DefaultTracerTest method testSpanEventHttp.

@Test
public void testSpanEventHttp() {
    DefaultTracer tracer = prepareTracer();
    tracer.reportAsExternal(HttpParameters.library("library").uri(URI.create("http://www.newrelic.com")).procedure("call").noInboundHeaders().build());
    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("library", spanEvent.getIntrinsics().get("component"));
    assertEquals("client", spanEvent.getIntrinsics().get("span.kind"));
    assertEquals("http://www.newrelic.com", spanEvent.getAgentAttributes().get("http.url"));
    assertEquals("call", spanEvent.getAgentAttributes().get("http.method"));
}
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 20 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class DefaultTracerTest method testExternalParameters.

@Test
public void testExternalParameters() throws URISyntaxException {
    TransactionActivity.clear();
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    TransactionActivity txa = TransactionActivity.get();
    Tracer root = new OtherRootTracer(tx, new ClassMethodSignature("com.newrelic.agent.TracedActivityTest", "makeTransaction", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
    txa.tracerStarted(root);
    final TransactionStats stats = root.getTransactionActivity().getTransactionStats();
    // http external
    final String library = "unittest";
    final URI uri = new URI("http://localhost");
    final String host = uri.getHost();
    final String procedure = "connect";
    int externalCount = 0;
    {
        // generic external
        DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
        assertExternal(stats, externalCount, host, library, procedure);
        // multiple calls to addExternalParameters should only apply the last call
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        // metrics should only be recorded when the tracer finishes
        assertExternal(stats, externalCount, host, library, procedure);
        assertEquals(externalCount, stats.getScopedStats().getOrCreateResponseTimeStats("External/" + host + "/" + library + "/" + procedure).getCallCount());
        tracer.finish(0, null);
        externalCount++;
        assertExternal(stats, externalCount, host, library, procedure);
        assertEquals(externalCount, stats.getScopedStats().getOrCreateResponseTimeStats("External/" + host + "/" + library + "/" + procedure).getCallCount());
    }
    final DatastoreVendor vendor = DatastoreVendor.MySQL;
    final String collection = "stores";
    final String operation = "select";
    final int port = 666;
    int datastoreCount = 0;
    {
        // datastore
        DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        tracer.reportAsExternal(DatastoreParameters.product(vendor.toString()).collection(collection).operation(operation).instance(host, port).build());
        assertDatastore(stats, datastoreCount, vendor.toString(), collection, operation, host, port);
        tracer.finish(0, null);
        datastoreCount++;
        assertDatastore(stats, datastoreCount, vendor.toString(), collection, operation, host, port);
        // http external should be unchanged
        assertExternal(stats, externalCount, host, library, procedure);
    }
    {
        // http + DT
        DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
        tracer.addOutboundRequestHeaders(new Outbound());
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        tracer.reportAsExternal(HttpParameters.library(library).uri(uri).procedure(procedure).inboundHeaders(new Inbound("Foo")).build());
        assertCat(tracer, false);
        assertExternal(stats, externalCount, host, library, procedure);
        tracer.finish(0, null);
        externalCount++;
        // DT is enabled, there should not be any CAT
        assertCat(tracer, false);
        // ExternalTransaction/localhost/12345/Foo
        assertExternal(stats, externalCount, host, library, procedure);
        assertEquals(0, stats.getScopedStats().getOrCreateResponseTimeStats("ExternalTransaction/" + host + "/12345/Foo").getCallCount());
    }
    {
        // last inboundHeaders win
        DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
        tracer.addOutboundRequestHeaders(new Outbound());
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        tracer.reportAsExternal(HttpParameters.library(library).uri(uri).procedure(procedure).inboundHeaders(new Inbound("Foo")).build());
        // headers trump the previous call
        tracer.readInboundResponseHeaders(new Inbound("Bar"));
        assertCat(tracer, false);
        assertExternal(stats, externalCount, host, library, procedure);
        tracer.finish(0, null);
        externalCount++;
        // DT is enabled, there should not be any CAT
        assertCat(tracer, false);
        // ExternalTransaction/localhost/12345/Foo
        assertExternal(stats, externalCount, host, library, procedure);
        assertEquals(0, stats.getScopedStats().getOrCreateResponseTimeStats("ExternalTransaction/" + host + "/12345/Bar").getCallCount());
    }
    {
        // set headers manually
        DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
        tracer.addOutboundRequestHeaders(new Outbound());
        tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
        // headers trump the previous call
        tracer.readInboundResponseHeaders(new Inbound("Baz"));
        assertCat(tracer, false);
        assertExternal(stats, externalCount, host, library, procedure);
        tracer.finish(0, null);
        externalCount++;
        // DT is enabled, there should not be any CAT
        assertCat(tracer, false);
        // ExternalTransaction/localhost/12345/Foo
        assertExternal(stats, externalCount, host, library, procedure);
        assertEquals(0, stats.getScopedStats().getOrCreateResponseTimeStats("ExternalTransaction/" + host + "/12345/Baz").getCallCount());
    }
    root.finish(0, null);
}
Also used : TransactionActivity(com.newrelic.agent.TransactionActivity) URI(java.net.URI) DatastoreVendor(com.newrelic.agent.bridge.datastore.DatastoreVendor) TransactionStats(com.newrelic.agent.stats.TransactionStats) Transaction(com.newrelic.agent.Transaction) 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