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