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)));
}
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());
}
}
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"));
}
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());
}
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());
}
Aggregations