Search in sources :

Example 6 with TracedMetricData

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

the class RabbitMQTest_Integration method testMessageListener.

@Test
public void testMessageListener() throws IOException, InterruptedException {
    final String queueName = UUID.randomUUID().toString();
    final String messageForListener = "Hello message listener!";
    channel.queueDeclare(queueName, false, false, true, true, Collections.<String, Object>emptyMap());
    channel.basicPublish(DEFAULT_EXCHANGE, queueName, new AMQP.BasicProperties(), messageForListener.getBytes());
    channel.basicConsume(queueName, new DefaultConsumer(channel) {

        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
            assertEquals(messageForListener, new String(body));
        }
    });
    // Let handleDelivery Transaction to finish.
    Thread.sleep(1000);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    String expectedTransactionName = String.format("OtherTransaction/Message/RabbitMQ/Queue/Named/%s", queueName);
    final Collection<String> transactionNames = introspector.getTransactionNames();
    assertTrue(transactionNames.contains(expectedTransactionName));
    Map<String, TracedMetricData> metrics = introspector.getMetricsForTransaction(expectedTransactionName);
    assertTrue(metrics.containsKey(String.format("MessageBroker/RabbitMQ/Queue/Consume/Named/%s", queueName)));
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) AMQP(com.rabbitmq.client.AMQP) Introspector(com.newrelic.agent.introspec.Introspector) IOException(java.io.IOException) Envelope(com.rabbitmq.client.Envelope) Test(org.junit.Test)

Example 7 with TracedMetricData

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

the class RabbitMQTest_Integration method testCat.

@Test
public void testCat() throws IOException, InterruptedException {
    final String queueName = UUID.randomUUID().toString();
    channel.queueDeclare(queueName, false, false, true, true, Collections.<String, Object>emptyMap());
    final String replyMessage = "reply";
    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());
        }
    });
    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 properties = new AMQP.BasicProperties();
                properties.setReplyTo(tempQueue);
                channel.basicPublish(DEFAULT_EXCHANGE, queueName, properties, "message".getBytes());
                QueueingConsumer queueingConsumer = new QueueingConsumer(channel);
                channel.basicConsume(tempQueue, true, queueingConsumer);
                // block
                QueueingConsumer.Delivery delivery = queueingConsumer.nextDelivery();
                assertEquals(replyMessage, new String(delivery.getBody()));
            } catch (IOException e) {
            } catch (InterruptedException e) {
            }
        }
    });
    thread.start();
    thread.join(2000);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    String senderTransactioName = "OtherTransaction/Category/Sender";
    String messageListenerTransactionName = String.format("OtherTransaction/Message/RabbitMQ/Queue/Named/%s", queueName);
    final Collection<String> transactionNames = introspector.getTransactionNames();
    assertTrue(transactionNames.contains(senderTransactioName));
    assertTrue(transactionNames.contains(messageListenerTransactionName));
    Map<String, TracedMetricData> senderMetrics = introspector.getMetricsForTransaction(senderTransactioName);
    Map<String, TracedMetricData> messageListenerMetrics = introspector.getMetricsForTransaction(messageListenerTransactionName);
    assertTrue(senderMetrics.containsKey(String.format("MessageBroker/RabbitMQ/Queue/Produce/Named/%s", queueName)));
    assertTrue(senderMetrics.containsKey("MessageBroker/RabbitMQ/Queue/Consume/Temp"));
    assertTrue(messageListenerMetrics.containsKey(String.format("MessageBroker/RabbitMQ/Queue/Consume/Named/%s", queueName)));
    assertTrue(messageListenerMetrics.containsKey("MessageBroker/RabbitMQ/Queue/Produce/Temp"));
    // Ideally, the block below could be replaced with the following line:
    // CatHelper.verifyOneSuccessfulCat(introspector, senderTransactioName, messageListenerTransactionName);
    {
        TransactionTrace senderTT = introspector.getTransactionTracesForTransaction(senderTransactioName).iterator().next();
        TransactionTrace messageListenerTT = introspector.getTransactionTracesForTransaction(messageListenerTransactionName).iterator().next();
        Map<String, Object> senderTTIntrinsics = senderTT.getIntrinsicAttributes();
        Map<String, Object> messageListenerTTIntrinsics = messageListenerTT.getIntrinsicAttributes();
        assertNotNull(senderTTIntrinsics.get("trip_id"));
        assertNotNull(senderTTIntrinsics.get("path_hash"));
        assertNotNull(getAttribute(senderTT, "transaction_guid"));
        assertNotNull(messageListenerTTIntrinsics.get("referring_transaction_guid"));
        assertNotNull(messageListenerTTIntrinsics.get("client_cross_process_id"));
        TransactionEvent senderEvent = introspector.getTransactionEvents(senderTransactioName).iterator().next();
        TransactionEvent messageListenerEvent = introspector.getTransactionEvents(messageListenerTransactionName).iterator().next();
        assertEquals(senderEvent.getMyGuid(), messageListenerEvent.getReferrerGuid());
    }
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) 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) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Map(java.util.Map) Test(org.junit.Test)

Example 8 with TracedMetricData

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

the class RabbitMQTest method testMessageListener.

@Test
public void testMessageListener() throws IOException, InterruptedException {
    final String queueName = UUID.randomUUID().toString();
    final String messageForListener = "Hello message listener!";
    channel.queueDeclare(queueName, false, false, false, true, Collections.<String, Object>emptyMap());
    channel.basicPublish(DEFAULT_EXCHANGE, queueName, new AMQP.BasicProperties(), messageForListener.getBytes());
    channel.basicConsume(queueName, new DefaultConsumer(channel) {

        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
            assertEquals(messageForListener, new String(body));
        }
    });
    // Let handleDelivery Transaction to finish.
    Thread.sleep(1000);
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    String expectedTransactionName = "OtherTransaction/Message/RabbitMQ/Exchange/Named/Default";
    final Collection<String> transactionNames = introspector.getTransactionNames();
    assertTrue(transactionNames.contains(expectedTransactionName));
    // Do not record consume metric, message has already been delivered
    Map<String, TracedMetricData> metrics = introspector.getMetricsForTransaction(expectedTransactionName);
    assertFalse(metrics.containsKey("MessageBroker/RabbitMQ/Exchange/Consume/Named/Default"));
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) AMQP(com.rabbitmq.client.AMQP) Introspector(com.newrelic.agent.introspec.Introspector) IOException(java.io.IOException) Envelope(com.rabbitmq.client.Envelope) Test(org.junit.Test)

Example 9 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, false, true, Collections.<String, Object>emptyMap());
    channel.queueBind(queueName, exchangeName, queueName);
    System.out.println("Queue name is " + 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 basicProperties = new AMQP.BasicProperties();
                basicProperties.setReplyTo(tempQueue);
                channel.basicPublish(exchangeName, queueName, basicProperties, "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)

Example 10 with TracedMetricData

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

the class QuartzSystemTest method ramJobStoreTransactionNameAndMetricTest.

@Test
public void ramJobStoreTransactionNameAndMetricTest() throws Exception {
    JobDetail detail = buildJobDetail();
    final Trigger trigger = TriggerBuilder.newTrigger().build();
    Scheduler scheduler = new StdSchedulerFactory().getScheduler();
    scheduler.start();
    scheduler.scheduleJob(detail, trigger);
    scheduler.shutdown();
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    String expectedTransactionName = "OtherTransaction/Java/org.quartz.simpl.RAMJobStore/acquireNextTriggers";
    Map<String, TracedMetricData> metrics = introspector.getMetricsForTransaction(expectedTransactionName);
    assertEquals(1, metrics.get("Java/org.quartz.simpl.RAMJobStore/acquireNextTriggers").getCallCount());
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) Scheduler(org.quartz.Scheduler) Introspector(com.newrelic.agent.introspec.Introspector) 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