use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.
the class VertxClient method testCat.
@Test
public void testCat() throws Exception {
try (HttpTestServer httpServer = HttpServerLocator.createAndStart()) {
cat(httpServer);
Introspector introspector = InstrumentationTestRunner.getIntrospector();
String host = httpServer.getEndPoint().getHost();
String txName = "OtherTransaction/Custom/com.nr.vertx.instrumentation.VertxClient/cat";
assertEquals(2, introspector.getFinishedTransactionCount(250));
Collection<String> names = introspector.getTransactionNames();
assertEquals(2, names.size());
assertTrue(names.contains(httpServer.getServerTransactionName()));
assertTrue(names.contains(txName));
// scoped metrics
assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "ExternalTransaction/" + host + "/" + httpServer.getCrossProcessId() + "/" + httpServer.getServerTransactionName()));
assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "Java/com.nr.vertx.instrumentation.VertxClient/cat"));
// unscoped metrics
assertEquals(1, MetricsHelper.getUnscopedMetricCount("ExternalTransaction/" + host + "/" + httpServer.getCrossProcessId() + "/" + httpServer.getServerTransactionName()));
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);
CatHelper.verifyOneSuccessfulCat(introspector, txName);
// 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());
}
}
use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.
the class VertxClient method assertExternal.
public void assertExternal(String transactionName, String host) {
Introspector introspector = InstrumentationTestRunner.getIntrospector();
Collection<ExternalRequest> externalRequests = introspector.getExternalRequests(transactionName);
ExternalRequest request = externalRequests.iterator().next();
assertEquals(host, request.getHostname());
assertEquals("Vertx-Client", request.getLibrary());
assertEquals("end", request.getOperation());
Collection<TransactionEvent> events = introspector.getTransactionEvents(transactionName);
TransactionEvent event = events.iterator().next();
assertTrue(event.getAttributes().containsKey("responseHandler"));
assertEquals(1, MetricsHelper.getScopedMetricCount(transactionName, "External/localhost/Vertx-Client/end"));
assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/localhost/Vertx-Client/end"));
Collection<TransactionEvent> transactionEvents = introspector.getTransactionEvents(transactionName);
assertEquals(1, transactionEvents.size());
TransactionEvent transactionEvent = transactionEvents.iterator().next();
assertEquals(1, transactionEvent.getExternalCallCount());
assertTrue(transactionEvent.getExternalDurationInSec() > 0);
// external rollups
assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/localhost/all"));
assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/allOther"));
assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/all"));
}
use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.
the class ExternalsForTransactionTest method testAddExternalsOneCall.
@Test
public void testAddExternalsOneCall() {
TransactionStats stats = new TransactionStats();
stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(5, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(5, TimeUnit.MILLISECONDS);
stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/secondlib").recordResponseTime(5, TimeUnit.MILLISECONDS);
Collection<Tracer> tracers = new ArrayList<>();
tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myop"));
tracers.add(createTracer("External/myhost/secondlib", "External/myhost/secondlib/seconop"));
ExternalsForTransaction exts = new ExternalsForTransaction();
exts.addExternals(true, stats, tracers);
Collection<ExternalRequest> actual = exts.getExternals();
Assert.assertEquals(2, actual.size());
Iterator<ExternalRequest> it = actual.iterator();
while (it.hasNext()) {
ExternalRequestImpl impl = (ExternalRequestImpl) it.next();
Assert.assertEquals(1, impl.getCount());
if (impl.getMetricName().equals("External/myhost/mylib")) {
Assert.assertEquals("myhost", impl.getHostname());
Assert.assertEquals("mylib", impl.getLibrary());
Assert.assertEquals("myop", impl.getOperation());
} else {
Assert.assertEquals("myhost", impl.getHostname());
Assert.assertEquals("secondlib", impl.getLibrary());
Assert.assertEquals("seconop", impl.getOperation());
}
}
}
use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.
the class ExternalsForTransactionTest method testAddExternalsTwoCallsSameOperation.
@Test
public void testAddExternalsTwoCallsSameOperation() {
TransactionStats stats = new TransactionStats();
stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
Collection<Tracer> tracers = new ArrayList<>();
tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myop"));
ExternalsForTransaction exts = new ExternalsForTransaction();
exts.addExternals(true, stats, tracers);
stats = new TransactionStats();
stats.getUnscopedStats().getOrCreateResponseTimeStats("External/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("External/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("External/myhost/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getScopedStats().getOrCreateResponseTimeStats("External/myhost/mylib").recordResponseTime(10, TimeUnit.MILLISECONDS);
tracers = new ArrayList<>();
tracers.add(createTracer("External/myhost/mylib", "External/myhost/mylib/myop"));
exts.addExternals(true, stats, tracers);
Collection<ExternalRequest> actual = exts.getExternals();
Assert.assertEquals(1, actual.size());
Iterator<ExternalRequest> it = actual.iterator();
while (it.hasNext()) {
ExternalRequestImpl impl = (ExternalRequestImpl) it.next();
Assert.assertEquals(2, impl.getCount());
Assert.assertEquals("myhost", impl.getHostname());
Assert.assertEquals("mylib", impl.getLibrary());
Assert.assertEquals("myop", impl.getOperation());
}
}
use of com.newrelic.agent.introspec.ExternalRequest in project newrelic-java-agent by newrelic.
the class HttpServerTest method testCatCallSetName.
@Test
public void testCatCallSetName() throws IOException, URISyntaxException {
Introspector intro = InstrumentationTestRunner.getIntrospector();
HttpRequestClass myClass = new HttpRequestClass();
myClass.performCatHttp(server.getEndPoint());
assertEquals(2, intro.getFinishedTransactionCount());
Collection<String> names = intro.getTransactionNames();
assertEquals(2, names.size());
String txName1 = "OtherTransaction/Custom/com.example.http.HttpRequestClass/performCatHttp";
String txName2 = "WebTransaction/Custom/ExternalHTTPServer";
assertTrue(names.contains(txName1));
assertTrue(names.contains(txName2));
Collection<ExternalRequest> externals = intro.getExternalRequests(txName1);
assertEquals(1, externals.size());
ExternalRequest req = externals.iterator().next();
assertEquals(1, req.getCount());
assertEquals("localhost", req.getHostname());
CatHelper.verifyOneSuccessfulCat(intro, txName1);
}
Aggregations