Search in sources :

Example 1 with TracedMetricData

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

the class OkHttp30Test method testExternal.

@Test
public void testExternal() throws Exception {
    URI endpoint = server.getEndPoint();
    String host1 = endpoint.getHost();
    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(".*OkHttp30Test.*")) {
            txOne = txName;
        }
    }
    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());
    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 : 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)

Example 2 with TracedMetricData

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

the class OkHttp35Test method testExternal.

@Test
public void testExternal() throws Exception {
    URI endpoint = server.getEndPoint();
    String host1 = endpoint.getHost();
    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(".*OkHttp35Test.*")) {
            txOne = txName;
        }
    }
    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)

Example 3 with TracedMetricData

use of com.newrelic.agent.introspec.TracedMetricData 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 4 with TracedMetricData

use of com.newrelic.agent.introspec.TracedMetricData 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 5 with TracedMetricData

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

the class RabbitMQTest method testCat.

@Test
public void testCat() throws IOException, InterruptedException {
    final Map<String, Object> deliveryHeaders = new HashMap<>();
    final Map<String, Object> consumerHeaders = new HashMap<>();
    final String queueName = UUID.randomUUID().toString();
    final String replyMessage = "reply";
    final String exchangeName = "MyFavoriteExchange";
    channel.exchangeDeclare(exchangeName, "topic");
    channel.queueDeclare(queueName, false, false, true, Collections.<String, Object>emptyMap());
    channel.queueBind(queueName, exchangeName, queueName);
    channel.basicConsume(queueName, new DefaultConsumer(channel) {

        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
            channel.basicPublish(DEFAULT_EXCHANGE, properties.getReplyTo(), new AMQP.BasicProperties(), replyMessage.getBytes());
            consumerHeaders.putAll(properties.getHeaders());
        }
    });
    Thread thread = new Thread(new Runnable() {

        @Override
        @Trace(dispatcher = true)
        public void run() {
            NewRelic.setTransactionName("Category", "Sender");
            try {
                String tempQueue = channel.queueDeclare().getQueue();
                AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties().builder();
                builder.replyTo(tempQueue);
                channel.basicPublish(exchangeName, queueName, builder.build(), "message".getBytes());
                QueueingConsumer queueingConsumer = new QueueingConsumer(channel);
                channel.basicConsume(tempQueue, true, queueingConsumer);
                // block
                QueueingConsumer.Delivery delivery = queueingConsumer.nextDelivery();
                deliveryHeaders.putAll(delivery.getProperties().getHeaders());
                assertEquals(replyMessage, new String(delivery.getBody()));
            } catch (IOException | InterruptedException ignored) {
            }
        }
    });
    thread.start();
    thread.join(2000);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    String senderTransactioName = "OtherTransaction/Category/Sender";
    String messageListenerTransactionName = "OtherTransaction/Message/RabbitMQ/Exchange/Named/MyFavoriteExchange";
    Collection<String> transactionNames = introspector.getTransactionNames();
    assertTrue(transactionNames.contains(senderTransactioName));
    assertTrue(transactionNames.contains(messageListenerTransactionName));
    Map<String, TracedMetricData> senderMetrics = introspector.getMetricsForTransaction(senderTransactioName);
    assertTrue(senderMetrics.containsKey("MessageBroker/RabbitMQ/Exchange/Produce/Named/MyFavoriteExchange"));
    assertTrue(senderMetrics.containsKey("MessageBroker/RabbitMQ/Exchange/Consume/Named/Default"));
    Map<String, TracedMetricData> messageListenerMetrics = introspector.getMetricsForTransaction(messageListenerTransactionName);
    // Do not record consume metric in listener
    assertFalse(messageListenerMetrics.containsKey("MessageBroker/RabbitMQ/Exchange/Consume/Named/MyFavoriteExchange"));
    assertTrue(messageListenerMetrics.containsKey("MessageBroker/RabbitMQ/Exchange/Produce/Named/Default"));
    // Test one-way CAT. Both transactions do a publish/consume
    assertTrue(consumerHeaders.containsKey("NewRelicTransaction"));
    assertTrue(consumerHeaders.containsKey("NewRelicID"));
    assertTrue(deliveryHeaders.containsKey("NewRelicTransaction"));
    assertTrue(deliveryHeaders.containsKey("NewRelicID"));
    TransactionEvent senderEvent = introspector.getTransactionEvents(senderTransactioName).iterator().next();
    TransactionEvent messageListenerEvent = introspector.getTransactionEvents(messageListenerTransactionName).iterator().next();
    assertEquals(senderEvent.getMyGuid(), messageListenerEvent.getReferrerGuid());
    assertEquals(senderEvent.getMyPathHash(), messageListenerEvent.getReferringPathHash());
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) HashMap(java.util.HashMap) QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Introspector(com.newrelic.agent.introspec.Introspector) IOException(java.io.IOException) Envelope(com.rabbitmq.client.Envelope) Trace(com.newrelic.api.agent.Trace) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) AMQP(com.rabbitmq.client.AMQP) Test(org.junit.Test)

Aggregations

TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)65 Test (org.junit.Test)58 Introspector (com.newrelic.agent.introspec.Introspector)51 Java7IncompatibleTest (com.newrelic.test.marker.Java7IncompatibleTest)15 URI (java.net.URI)12 TransactionEvent (com.newrelic.agent.introspec.TransactionEvent)10 ExternalRequest (com.newrelic.agent.introspec.ExternalRequest)7 Tracer (com.newrelic.agent.tracers.Tracer)7 TransactionTrace (com.newrelic.agent.introspec.TransactionTrace)6 AMQP (com.rabbitmq.client.AMQP)6 DefaultConsumer (com.rabbitmq.client.DefaultConsumer)6 Envelope (com.rabbitmq.client.Envelope)6 IOException (java.io.IOException)6 ActorSystem (akka.actor.ActorSystem)5 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)4 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)4 Vertx (io.vertx.core.Vertx)4 HttpServer (io.vertx.core.http.HttpServer)4 TraceSegment (com.newrelic.agent.introspec.TraceSegment)3 Trace (com.newrelic.api.agent.Trace)3