use of com.newrelic.agent.introspec.TransactionEvent in project newrelic-java-agent by newrelic.
the class ValidationHelper method validateExceptionGrpcInteraction.
static void validateExceptionGrpcInteraction(TestServer server, String clientTxName, String serverTxName, String fullMethod, String grpcType, String name, int status) {
checkTransactions(2);
Introspector introspector = InstrumentationTestRunner.getIntrospector();
String externalTxSegmentName = "ExternalTransaction/localhost/" + getCrossProcessId() + "/" + serverTxName;
// Client side
Collection<TransactionTrace> clientTransactionTrace = introspector.getTransactionTracesForTransaction(clientTxName);
assertEquals(1, clientTransactionTrace.size());
TransactionTrace trace = clientTransactionTrace.iterator().next();
boolean foundSegment = false;
for (TraceSegment segment : trace.getInitialTraceSegment().getChildren()) {
// Verify external request exists and is valid
if (segment.getClassName().equals("External")) {
assertEquals(externalTxSegmentName, segment.getName());
assertEquals("grpc://localhost:" + server.getPort() + "/" + fullMethod, segment.getUri());
assertEquals(1, segment.getCallCount());
assertEquals("", segment.getMethodName());
assertEquals(grpcType, segment.getTracerAttributes().get("grpc.type"));
assertEquals("gRPC", segment.getTracerAttributes().get("component"));
assertEquals(fullMethod, segment.getTracerAttributes().get("http.method"));
foundSegment = true;
}
}
assertTrue("Unable to find client side External/ segment", foundSegment);
// Server side
Collection<TransactionTrace> serverTransactionTrace = introspector.getTransactionTracesForTransaction(serverTxName);
assertEquals(1, serverTransactionTrace.size());
TransactionTrace serverTrace = serverTransactionTrace.iterator().next();
TraceSegment rootSegment = serverTrace.getInitialTraceSegment();
assertTrue(rootSegment.getName().endsWith(fullMethod));
assertEquals(1, rootSegment.getCallCount());
assertEquals(fullMethod, rootSegment.getTracerAttributes().get("request.method"));
assertEquals(status, rootSegment.getTracerAttributes().get("response.status"));
assertEquals(grpcType, rootSegment.getTracerAttributes().get("grpc.type"));
// Custom attributes (to test tracing into customer code)
Collection<TransactionEvent> serverTxEvents = introspector.getTransactionEvents(serverTxName);
assertEquals(1, serverTxEvents.size());
TransactionEvent serverTxEvent = serverTxEvents.iterator().next();
assertNotNull(serverTxEvent);
assertEquals(status, serverTxEvent.getAttributes().get("response.status"));
assertEquals("grpc://localhost:" + server.getPort() + "/" + fullMethod, serverTxEvent.getAttributes().get("request.uri"));
}
use of com.newrelic.agent.introspec.TransactionEvent in project newrelic-java-agent by newrelic.
the class HttpClient31Test method testExternal.
@Test
public void testExternal() throws Exception {
httpClientExternal("http://localhost:" + server.getEndPoint().getPort());
Introspector introspector = InstrumentationTestRunner.getIntrospector();
Assert.assertEquals(2, introspector.getFinishedTransactionCount());
String txOne = "OtherTransaction/Custom/com.nr.agent.instrumentation.httpclient.HttpClient31Test/httpClientExternal";
Assert.assertEquals(1, MetricsHelper.getScopedMetricCount(txOne, "External/localhost/CommonsHttp/execute"));
Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/localhost/CommonsHttp/execute"));
// external rollups
Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/localhost/all"));
Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/allOther"));
Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/all"));
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("localhost", externalRequest.getHostname());
Assert.assertEquals("CommonsHttp", externalRequest.getLibrary());
Assert.assertEquals("execute", externalRequest.getOperation());
Assert.assertEquals(Integer.valueOf(200), externalRequest.getStatusCode());
Assert.assertEquals("OK", externalRequest.getStatusText());
}
use of com.newrelic.agent.introspec.TransactionEvent in project newrelic-java-agent by newrelic.
the class HttpClient4Test method testExternal.
@Test
public void testExternal() throws Exception {
URI endpoint = server.getEndPoint();
String host1 = endpoint.getHost();
httpClientExternal(endpoint.toString(), false);
Introspector introspector = InstrumentationTestRunner.getIntrospector();
Assert.assertEquals(2, introspector.getFinishedTransactionCount());
String txOne = null;
for (String txName : introspector.getTransactionNames()) {
if (txName.matches(".*HttpClient4Test.*")) {
txOne = txName;
}
}
Assert.assertNotNull("Transaction not found", txOne);
Assert.assertEquals(1, MetricsHelper.getScopedMetricCount(txOne, "External/" + host1 + "/CommonsHttp/execute"));
Assert.assertEquals(1, MetricsHelper.getUnscopedMetricCount("External/" + host1 + "/CommonsHttp/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"));
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("CommonsHttp", externalRequest.getLibrary());
Assert.assertEquals("execute", externalRequest.getOperation());
}
use of com.newrelic.agent.introspec.TransactionEvent in project newrelic-java-agent by newrelic.
the class HttpAsyncClient4Test method testCat.
@Test
public void testCat() throws IOException, InterruptedException, ExecutionException {
Introspector introspector = InstrumentationTestRunner.getIntrospector();
httpClientExternal(endpoint.toURL().toString(), true);
// transaction
String txName = "OtherTransaction/Custom/com.nr.agent.instrumentation.httpasyncclient4.HttpAsyncClient4Test/httpClientExternal";
assertEquals(2, introspector.getFinishedTransactionCount());
Collection<String> names = introspector.getTransactionNames();
assertEquals(2, names.size());
assertTrue(names.contains(server.getServerTransactionName()));
assertTrue(names.contains(txName));
// scoped metrics
assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "ExternalTransaction/" + host + "/" + server.getCrossProcessId() + "/" + server.getServerTransactionName()));
assertEquals(1, MetricsHelper.getScopedMetricCount(txName, "Java/com.nr.agent.instrumentation.httpasyncclient4.HttpAsyncClient4Test/httpClientExternal"));
// unscoped metrics
assertEquals(1, MetricsHelper.getUnscopedMetricCount("ExternalTransaction/" + host + "/" + server.getCrossProcessId() + "/" + server.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());
Assert.assertEquals(Integer.valueOf(200), externalRequest.getStatusCode());
Assert.assertEquals("OK", externalRequest.getStatusText());
}
use of com.newrelic.agent.introspec.TransactionEvent in project newrelic-java-agent by newrelic.
the class HystrixTestUtils method verifyEvent.
public static void verifyEvent(String txClass, TimeEvaluation eval) {
final String txName = InstrumentationTestRunner.getIntrospector().getTransactionNames().iterator().next();
Assert.assertEquals("OtherTransaction/Custom/" + txClass + "/runCommand", txName);
// events
Assert.assertEquals(0, InstrumentationTestRunner.getIntrospector().getCustomEventTypes().size());
Collection<TransactionEvent> events = InstrumentationTestRunner.getIntrospector().getTransactionEvents(txName);
Assert.assertEquals(1, events.size());
TransactionEvent event = events.iterator().next();
Assert.assertEquals(txName, event.getName());
switch(eval) {
case TOTAL_TIME_EQUAL:
Assert.assertEquals(event.getDurationInSec(), event.getTotalTimeInSec(), .0001);
break;
case TOTAL_TIME_LESS:
Assert.assertTrue(event.getDurationInSec() > event.getTotalTimeInSec());
break;
case TOTAL_TIME_GREATER:
Assert.assertTrue(event.getDurationInSec() < event.getTotalTimeInSec());
}
}
Aggregations