Search in sources :

Example 16 with ExternalRequest

use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.

the class VertxClient method testCat.

@Test
public void testCat() throws Exception {
    try (HttpTestServer httpServer = HttpServerLocator.createAndStart()) {
        cat(httpServer);
        Introspector introspector = InstrumentationTestRunner.getIntrospector();
        String host = httpServer.getEndPoint().getHost();
        String txName = "OtherTransaction/Custom/com.nr.vertx.instrumentation.VertxClient/cat";
        assertEquals(2, introspector.getFinishedTransactionCount(250));
        Collection<String> names = introspector.getTransactionNames();
        assertEquals(2, names.size());
        assertTrue(names.contains(httpServer.getServerTransactionName()));
        assertTrue(names.contains(txName));
        // scoped metrics
        assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "ExternalTransaction/" + host + "/" + httpServer.getCrossProcessId() + "/" + httpServer.getServerTransactionName()));
        assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "Java/com.nr.vertx.instrumentation.VertxClient/cat"));
        // unscoped metrics
        assertEquals(1, MetricsHelper.getUnscopedMetricCount("ExternalTransaction/" + host + "/" + httpServer.getCrossProcessId() + "/" + httpServer.getServerTransactionName()));
        assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host + "/all"));
        assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/all"));
        assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/allOther"));
        // events
        Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(txName);
        assertEquals(1, transactionEvents.size());
        TransactionEvent transactionEvent = transactionEvents.iterator().next();
        assertEquals(1, transactionEvent.getExternalCallCount());
        assertTrue(transactionEvent.getExternalDurationInSec() > 0);
        CatHelper.verifyOneSuccessfulCat(introspector, txName);
        // external request information
        Collection<ExternalRequest> externalRequests = introspector.getExternalRequests(txName);
        assertEquals(1, externalRequests.size());
        ExternalRequest externalRequest = externalRequests.iterator().next();
        assertEquals(1, externalRequest.getCount());
        assertEquals(host, externalRequest.getHostname());
    }
}
Also used : TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) Introspector(com.newrelic.agent.introspec.Introspector) HttpTestServer(com.newrelic.agent.introspec.HttpTestServer) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

Example 17 with ExternalRequest

use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.

the class VertxClient method assertExternal.

public void assertExternal(String transactionName, String host) {
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    Collection<ExternalRequest> externalRequests = introspector.getExternalRequests(transactionName);
    ExternalRequest request = externalRequests.iterator().next();
    assertEquals(host, request.getHostname());
    assertEquals("Vertx-Client", request.getLibrary());
    assertEquals("end", request.getOperation());
    Collection<TransactionEvent> events = introspector.getTransactionEvents(transactionName);
    TransactionEvent event = events.iterator().next();
    assertTrue(event.getAttributes().containsKey("responseHandler"));
    assertEquals(1, MetricsHelper.getScopedMetricCount(transactionName, "External/localhost/Vertx-Client/end"));
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/localhost/Vertx-Client/end"));
    Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(transactionName);
    assertEquals(1, transactionEvents.size());
    TransactionEvent transactionEvent = transactionEvents.iterator().next();
    assertEquals(1, transactionEvent.getExternalCallCount());
    assertTrue(transactionEvent.getExternalDurationInSec() > 0);
    // external rollups
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/localhost/all"));
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/allOther"));
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/all"));
}
Also used : TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) Introspector(com.newrelic.agent.introspec.Introspector) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest)

Example 18 with ExternalRequest

use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.

the class ExternalsForTransactionTest method testAddExternalsOneCall.

@Test
public void testAddExternalsOneCall() {
    TransactionStats stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/secondlib").recordResponseTime(5, TimeUnit.MILLISECONDS);
    Collection<Tracer> tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myop"));
    tracers.add(createTracer("External/myhost/secondlib", "External/myhost/secondlib/seconop"));
    ExternalsForTransaction exts = new ExternalsForTransaction();
    exts.addExternals(true, stats, tracers);
    Collection<ExternalRequest> actual = exts.getExternals();
    Assert.assertEquals(2, actual.size());
    Iterator<ExternalRequest> it = actual.iterator();
    while (it.hasNext()) {
        ExternalRequestImpl impl = (ExternalRequestImpl) it.next();
        Assert.assertEquals(1, impl.getCount());
        if (impl.getMetricName().equals("External/myhost/mylib")) {
            Assert.assertEquals("myhost", impl.getHostname());
            Assert.assertEquals("mylib", impl.getLibrary());
            Assert.assertEquals("myop", impl.getOperation());
        } else {
            Assert.assertEquals("myhost", impl.getHostname());
            Assert.assertEquals("secondlib", impl.getLibrary());
            Assert.assertEquals("seconop", impl.getOperation());
        }
    }
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ArrayList(java.util.ArrayList) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

Example 19 with ExternalRequest

use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.

the class ExternalsForTransactionTest method testAddExternalsTwoCallsSameOperation.

@Test
public void testAddExternalsTwoCallsSameOperation() {
    TransactionStats stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    Collection<Tracer> tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myop"));
    ExternalsForTransaction exts = new ExternalsForTransaction();
    exts.addExternals(true, stats, tracers);
    stats = new TransactionStats();
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
    stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
    tracers = new ArrayList<>();
    tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myop"));
    exts.addExternals(true, stats, tracers);
    Collection<ExternalRequest> actual = exts.getExternals();
    Assert.assertEquals(1, actual.size());
    Iterator<ExternalRequest> it = actual.iterator();
    while (it.hasNext()) {
        ExternalRequestImpl impl = (ExternalRequestImpl) it.next();
        Assert.assertEquals(2, impl.getCount());
        Assert.assertEquals("myhost", impl.getHostname());
        Assert.assertEquals("mylib", impl.getLibrary());
        Assert.assertEquals("myop", impl.getOperation());
    }
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ArrayList(java.util.ArrayList) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

Example 20 with ExternalRequest

use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.

the class HttpServerTest method testCatCallSetName.

@Test
public void testCatCallSetName() throws IOException, URISyntaxException {
    Introspector intro = InstrumentationTestRunner.getIntrospector();
    HttpRequestClass myClass = new HttpRequestClass();
    myClass.performCatHttp(server.getEndPoint());
    assertEquals(2, intro.getFinishedTransactionCount());
    Collection<String> names = intro.getTransactionNames();
    assertEquals(2, names.size());
    String txName1 = "OtherTransaction/Custom/com.example.http.HttpRequestClass/performCatHttp";
    String txName2 = "WebTransaction/Custom/ExternalHTTPServer";
    assertTrue(names.contains(txName1));
    assertTrue(names.contains(txName2));
    Collection<ExternalRequest> externals = intro.getExternalRequests(txName1);
    assertEquals(1, externals.size());
    ExternalRequest req = externals.iterator().next();
    assertEquals(1, req.getCount());
    assertEquals("localhost", req.getHostname());
    CatHelper.verifyOneSuccessfulCat(intro, txName1);
}
Also used : HttpRequestClass(com.example.http.HttpRequestClass) Introspector(com.newrelic.agent.introspec.Introspector) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

Aggregations

ExternalRequest (com.newrelic.agent.introspec.ExternalRequest)55 Test (org.junit.Test)52 Introspector (com.newrelic.agent.introspec.Introspector)51 TransactionEvent (com.newrelic.agent.introspec.TransactionEvent)44 URI (java.net.URI)34 TraceSegment (com.newrelic.agent.introspec.TraceSegment)10 TransactionTrace (com.newrelic.agent.introspec.TransactionTrace)10 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)7 Java7IncompatibleTest (com.newrelic.test.marker.Java7IncompatibleTest)6 Java10IncompatibleTest (com.newrelic.test.marker.Java10IncompatibleTest)5 Java11IncompatibleTest (com.newrelic.test.marker.Java11IncompatibleTest)5 Java12IncompatibleTest (com.newrelic.test.marker.Java12IncompatibleTest)5 Java13IncompatibleTest (com.newrelic.test.marker.Java13IncompatibleTest)5 Java14IncompatibleTest (com.newrelic.test.marker.Java14IncompatibleTest)5 Java15IncompatibleTest (com.newrelic.test.marker.Java15IncompatibleTest)5 Java16IncompatibleTest (com.newrelic.test.marker.Java16IncompatibleTest)5 Java17IncompatibleTest (com.newrelic.test.marker.Java17IncompatibleTest)5 Java9IncompatibleTest (com.newrelic.test.marker.Java9IncompatibleTest)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5