Search in sources :

Example 26 with TraceSegment

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

the class NingAsyncHttpClient10Tests method testError.

@Test
public void testError() throws Exception {
    String host = "www.thiswebsitedoesntexistreallyatallipromise.com";
    String url = "http://" + host + "/";
    int status = makeAsyncRequest(url);
    assertEquals(-1, status);
    // transaction
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    assertEquals(1, introspector.getFinishedTransactionCount(TIMEOUT));
    String txName = introspector.getTransactionNames().iterator().next();
    // scoped metrics
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "External/" + host + "/AsyncHttpClient/onThrowable"));
    // unscoped metrics
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host + "/AsyncHttpClient/onThrowable"));
    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 ("External".equals(attributes.get("async_context"))) {
            assertEquals("", segment.getMethodName());
            assertEquals("External Request", segment.getClassName());
            assertEquals("External/" + host + "/AsyncHttpClient/onThrowable", 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("AsyncHttpClient", externalRequest.getLibrary());
    assertEquals("onThrowable", externalRequest.getOperation());
}
Also used : TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Introspector(com.newrelic.agent.introspec.Introspector) TraceSegment(com.newrelic.agent.introspec.TraceSegment) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

Example 27 with TraceSegment

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

the class NingAsyncHttpClient11Tests method testError.

@Test
public void testError() throws Exception {
    String host = "www.thiswebsitedoesntexistreallyatallipromise.com";
    String url = "http://" + host + "/";
    int status = makeAsyncRequest(url);
    assertEquals(-1, status);
    // transaction
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    assertEquals(1, introspector.getFinishedTransactionCount(10000));
    String txName = introspector.getTransactionNames().iterator().next();
    // scoped metrics
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "External/" + host + "/AsyncHttpClient/onThrowable"));
    // unscoped metrics
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host + "/AsyncHttpClient/onThrowable"));
    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 ("External".equals(attributes.get("async_context"))) {
            assertEquals("", segment.getMethodName());
            assertEquals("External Request", segment.getClassName());
            assertEquals("External/" + host + "/AsyncHttpClient/onThrowable", 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("AsyncHttpClient", externalRequest.getLibrary());
}
Also used : TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Introspector(com.newrelic.agent.introspec.Introspector) TraceSegment(com.newrelic.agent.introspec.TraceSegment) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) Test(org.junit.Test)

Example 28 with TraceSegment

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

the class NingAsyncHttpClient11Tests 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();
    int status = makeAsyncRequest(url + "?no-transaction=true");
    assertEquals(200, status);
    // transaction
    assertEquals(1, introspector.getFinishedTransactionCount(10000));
    String txName = introspector.getTransactionNames().iterator().next();
    // scoped metrics
    assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "External/" + host + "/AsyncHttpClient/onCompleted"));
    // unscoped metrics
    assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host + "/AsyncHttpClient/onCompleted"));
    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();
        Object asyncContext = attributes.get("async_context");
        if (asyncContext != null && asyncContext.equals("External")) {
            assertEquals("", segment.getMethodName());
            assertEquals("External Request", segment.getClassName());
            assertEquals("External/" + host + "/AsyncHttpClient/onCompleted", 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("AsyncHttpClient", externalRequest.getLibrary());
    assertEquals("onCompleted", externalRequest.getOperation());
    assertEquals(Integer.valueOf(200), externalRequest.getStatusCode());
    assertEquals("OK", externalRequest.getStatusText());
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) URI(java.net.URI) TraceSegment(com.newrelic.agent.introspec.TraceSegment) ExternalRequest(com.newrelic.agent.introspec.ExternalRequest) TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Test(org.junit.Test)

Example 29 with TraceSegment

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

the class PlayAsyncHttpClientTests method testWithFilterHeaders.

@Test
public void testWithFilterHeaders() 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();
    makeAsyncRequestWithFilterHeaders(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 30 with TraceSegment

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

the class PlayAsyncHttpClientTests method testError.

@Test
public void testError() {
    String host = "www.thiswebsitedoesntexistreallyatallipromise.com";
    String url = "http://" + host + "/";
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger result = new AtomicInteger();
    makeAsyncRequest(url, standaloneWSResponse -> {
        result.set(standaloneWSResponse.status());
        latch.countDown();
    });
    assertEquals(0, result.get());
    // transaction
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    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 ("segment-api".equals(attributes.get("async_context"))) {
            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());
}
Also used : Introspector(com.newrelic.agent.introspec.Introspector) CountDownLatch(java.util.concurrent.CountDownLatch) 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)

Aggregations

TraceSegment (com.newrelic.agent.introspec.TraceSegment)33 TransactionTrace (com.newrelic.agent.introspec.TransactionTrace)24 Introspector (com.newrelic.agent.introspec.Introspector)19 Test (org.junit.Test)19 TransactionEvent (com.newrelic.agent.introspec.TransactionEvent)14 ExternalRequest (com.newrelic.agent.introspec.ExternalRequest)10 URI (java.net.URI)7 Java10IncompatibleTest (com.newrelic.test.marker.Java10IncompatibleTest)6 Java11IncompatibleTest (com.newrelic.test.marker.Java11IncompatibleTest)6 Java12IncompatibleTest (com.newrelic.test.marker.Java12IncompatibleTest)6 Java13IncompatibleTest (com.newrelic.test.marker.Java13IncompatibleTest)6 Java14IncompatibleTest (com.newrelic.test.marker.Java14IncompatibleTest)6 Java15IncompatibleTest (com.newrelic.test.marker.Java15IncompatibleTest)6 Java16IncompatibleTest (com.newrelic.test.marker.Java16IncompatibleTest)6 Java17IncompatibleTest (com.newrelic.test.marker.Java17IncompatibleTest)6 Java9IncompatibleTest (com.newrelic.test.marker.Java9IncompatibleTest)6 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)3 Tracer (com.newrelic.agent.tracers.Tracer)3