Search in sources :

Example 11 with ExternalRequest

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

the class OkHttp4Test method testExternal.

@Test
public void testExternal() throws Exception {
    URI endpoint = server.getEndPoint();
    httpClientExternal(endpoint.toString(), false, 2000);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    Assert.assertEquals(2, introspector.getFinishedTransactionCount());
    String txOne = null;
    for (String txName : introspector.getTransactionNames()) {
        if (txName.matches(".*OkHttp4Test.*")) {
            txOne = txName;
        }
    }
    String host1 = endpoint.getHost();
    Assert.assertNotNull("Transaction not found", txOne);
    Assert.assertEquals(1, MetricsHelper.getScopedMetricCount(txOne, "External/" + host1 + "/OkHttp/execute"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host1 + "/OkHttp/execute"));
    // external rollups
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host1 + "/all"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/allOther"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/all"));
    // verify timing of External/all metrics
    TracedMetricData externalMetrics = InstrumentationTestRunner.getIntrospector().getUnscopedMetrics().get("External/all");
    assertNotNull(externalMetrics);
    assertTrue(externalMetrics.getTotalTimeInSec() > 2);
    Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(txOne);
    Assert.assertEquals(1, transactionEvents.size());
    TransactionEvent transactionEvent = transactionEvents.iterator().next();
    Assert.assertEquals(1, transactionEvent.getExternalCallCount());
    Assert.assertTrue(transactionEvent.getExternalDurationInSec() > 0);
    Collection<ExternalRequest> externalRequests = introspector.getExternalRequests(txOne);
    Assert.assertEquals(1, externalRequests.size());
    ExternalRequest externalRequest = externalRequests.iterator().next();
    Assert.assertEquals(1, externalRequest.getCount());
    Assert.assertEquals(host1, externalRequest.getHostname());
    Assert.assertEquals("OkHttp", externalRequest.getLibrary());
    Assert.assertEquals("execute", externalRequest.getOperation());
    Assert.assertEquals(Integer.valueOf(200), externalRequest.getStatusCode());
    // the test server does return the trailing space, this client does not trim it
    Assert.assertEquals("OK ", externalRequest.getStatusText());
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) Introspector(com.newrelic.agent.introspec.Introspector) URI(java.net.URI) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 12 with ExternalRequest

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

the class OkHttp44Test method testCat.

@Test
public void testCat() throws Exception {
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    URI endpoint = server.getEndPoint();
    httpClientExternal(endpoint.toURL().toString());
    // transaction
    assertEquals(2, introspector.getFinishedTransactionCount());
    Collection<String> names = introspector.getTransactionNames();
    assertEquals(2, names.size());
    assertTrue(names.contains(server.getServerTransactionName()));
    String txName = "OtherTransaction/Custom/" + this.getClass().getName() + "/httpClientExternal";
    assertTrue(names.contains(txName));
    // scoped metrics
    String host = endpoint.getHost();
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "ExternalTransaction/" + host + "/" + server.getCrossProcessId() + "/" + server.getServerTransactionName()));
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "Java/" + this.getClass().getName() + "/httpClientExternal"));
    // unscoped metrics
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("ExternalTransaction/" + host + "/" + server.getCrossProcessId() + "/" + server.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());
    assertEquals(Integer.valueOf(200), externalRequest.getStatusCode());
    // the test server does return the trailing space, this client does not trim it
    assertEquals("OK ", externalRequest.getStatusText());
}
Also used : TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) Introspector(com.newrelic.agent.introspec.Introspector) URI(java.net.URI) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 13 with ExternalRequest

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

the class OkHttp44Test method testExternal.

@Test
public void testExternal() throws Exception {
    URI endpoint = server.getEndPoint();
    httpClientExternal(endpoint.toString(), false, 2000);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    Assert.assertEquals(2, introspector.getFinishedTransactionCount());
    String txOne = null;
    for (String txName : introspector.getTransactionNames()) {
        if (txName.matches(".*OkHttp44Test.*")) {
            txOne = txName;
        }
    }
    String host1 = endpoint.getHost();
    Assert.assertNotNull("Transaction not found", txOne);
    Assert.assertEquals(1, MetricsHelper.getScopedMetricCount(txOne, "External/" + host1 + "/OkHttp/execute"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host1 + "/OkHttp/execute"));
    // external rollups
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host1 + "/all"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/allOther"));
    Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/all"));
    // verify timing of External/all metrics
    TracedMetricData externalMetrics = InstrumentationTestRunner.getIntrospector().getUnscopedMetrics().get("External/all");
    assertNotNull(externalMetrics);
    assertTrue(externalMetrics.getTotalTimeInSec() > 2);
    Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(txOne);
    Assert.assertEquals(1, transactionEvents.size());
    TransactionEvent transactionEvent = transactionEvents.iterator().next();
    Assert.assertEquals(1, transactionEvent.getExternalCallCount());
    Assert.assertTrue(transactionEvent.getExternalDurationInSec() > 0);
    Collection<ExternalRequest> externalRequests = introspector.getExternalRequests(txOne);
    Assert.assertEquals(1, externalRequests.size());
    ExternalRequest externalRequest = externalRequests.iterator().next();
    Assert.assertEquals(1, externalRequest.getCount());
    Assert.assertEquals(host1, externalRequest.getHostname());
    Assert.assertEquals("OkHttp", externalRequest.getLibrary());
    Assert.assertEquals("execute", externalRequest.getOperation());
    Assert.assertEquals(Integer.valueOf(200), externalRequest.getStatusCode());
    // the test server does return the trailing space, this client does not trim it
    Assert.assertEquals("OK ", externalRequest.getStatusText());
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) Introspector(com.newrelic.agent.introspec.Introspector) URI(java.net.URI) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 14 with ExternalRequest

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

the class PlayAsyncHttpClientTests method testSuccess.

@Test
public void testSuccess() throws Exception {
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    URI endpoint = server.getEndPoint();
    String host = endpoint.getHost();
    String url = endpoint.toURL().toExternalForm();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger result = new AtomicInteger();
    makeAsyncRequest(url + "?no-transaction=true", standaloneWSResponse -> {
        result.set(standaloneWSResponse.status());
        latch.countDown();
    });
    latch.await(30, TimeUnit.SECONDS);
    assertEquals(200, result.get());
    // transaction
    assertEquals(1, introspector.getFinishedTransactionCount(TimeUnit.SECONDS.toMillis(30)));
    String txName = introspector.getTransactionNames().iterator().next();
    // scoped metrics
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "External/" + host + "/PlayWS/get"));
    // unscoped metrics
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host + "/PlayWS/get"));
    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);
    // traces
    Collection<TransactionTrace> traces = introspector.getTransactionTracesForTransaction(txName);
    assertEquals(1, traces.size());
    TransactionTrace trace = traces.iterator().next();
    for (TraceSegment segment : trace.getInitialTraceSegment().getChildren()) {
        Map<String, Object> attributes = segment.getTracerAttributes();
        if (attributes.get("async_context").equals("segment-api")) {
            assertEquals("", segment.getMethodName());
            assertEquals("PlayWS", segment.getClassName());
            assertEquals("External/" + host + "/PlayWS/get", segment.getName());
            assertEquals(url, segment.getUri());
            assertEquals(1, segment.getCallCount());
        }
    }
    // 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());
    assertEquals("PlayWS", externalRequest.getLibrary());
    assertEquals("get", externalRequest.getOperation());
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) TraceSegment(com.newrelic.agent.introspec.TraceSegment) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Java10IncompatibleTest(com.newrelic.test.marker.Java10IncompatibleTest) Java13IncompatibleTest(com.newrelic.test.marker.Java13IncompatibleTest) Java16IncompatibleTest(com.newrelic.test.marker.Java16IncompatibleTest) Java9IncompatibleTest(com.newrelic.test.marker.Java9IncompatibleTest) Java17IncompatibleTest(com.newrelic.test.marker.Java17IncompatibleTest) Java14IncompatibleTest(com.newrelic.test.marker.Java14IncompatibleTest) Test(org.junit.Test) Java11IncompatibleTest(com.newrelic.test.marker.Java11IncompatibleTest) Java15IncompatibleTest(com.newrelic.test.marker.Java15IncompatibleTest) Java12IncompatibleTest(com.newrelic.test.marker.Java12IncompatibleTest)

Example 15 with ExternalRequest

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

the class WebClientTest method testCatBaseUrl.

@Test
public void testCatBaseUrl() {
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    final String response = makeBaseUrlCatRequest(catEndpoint).block().bodyToMono(String.class).block();
    assertEquals("<html><body><h1>SuccessfulResponse</h1>\n</body></html>\n", response);
    // transaction
    String txName = "OtherTransaction/Custom/com.nr.instrumentation.WebClientTest/makeBaseUrlCatRequest";
    assertEquals(2, introspector.getFinishedTransactionCount(// One transaction is the one we care about and the other is the server-side CAT tx
    TIMEOUT));
    Collection<String> names = introspector.getTransactionNames();
    assertEquals(2, names.size());
    assertTrue(names.contains(server.getServerTransactionName()));
    assertTrue(names.contains(txName));
    // scoped metrics
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "ExternalTransaction/" + host + "/" + server.getCrossProcessId() + "/" + server.getServerTransactionName()));
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "Java/com.nr.instrumentation.WebClientTest/makeBaseUrlCatRequest"));
    // unscoped metrics
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("ExternalTransaction/" + host + "/" + server.getCrossProcessId() + "/" + server.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) 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