use of com.newrelic.agent.introspec.TransactionTrace in project newrelic-java-agent by newrelic.
the class CassandraInstrumented method testSyncBatchStatementRequests.
@Test
public void testSyncBatchStatementRequests() {
// Given
Introspector introspector = InstrumentationTestRunner.getIntrospector();
DatastoreHelper helper = new DatastoreHelper(DatastoreVendor.Cassandra.toString());
// When
CassandraTestUtils.batchStatementRequests(cassandra.session);
// Then
assertEquals(1, introspector.getFinishedTransactionCount(1000));
assertEquals(1, introspector.getTransactionNames().size());
String transactionName = introspector.getTransactionNames().stream().findFirst().orElse("");
Collection<TransactionTrace> traces = introspector.getTransactionTracesForTransaction(transactionName);
List<TraceSegment> traceSegments = traces.stream().findFirst().map(TransactionTrace::getInitialTraceSegment).map(TraceSegment::getChildren).orElse(Collections.emptyList());
helper.assertScopedOperationMetricCount(transactionName, "BATCH", 1);
helper.assertAggregateMetrics();
helper.assertUnscopedOperationMetricCount("BATCH", 1);
assertEquals(1, traces.size());
assertEquals(1, traceSegments.size());
traceSegments.stream().map(TraceSegment::getTracerAttributes).forEach(x -> {
assertNotNull(x.get("host"));
assertNotNull(x.get("port_path_or_id"));
assertNotNull(x.get("db.instance"));
});
}
use of com.newrelic.agent.introspec.TransactionTrace in project newrelic-java-agent by newrelic.
the class HystrixTestUtils method verifyOneHystrixTransactionTrace.
public static void verifyOneHystrixTransactionTrace(String command, CallType type) {
final String txName = InstrumentationTestRunner.getIntrospector().getTransactionNames().iterator().next();
// transaction trace
Collection<TransactionTrace> traces = InstrumentationTestRunner.getIntrospector().getTransactionTracesForTransaction(txName);
Assert.assertEquals(1, traces.size());
TransactionTrace trace = traces.iterator().next();
TraceSegment segment = trace.getInitialTraceSegment();
Assert.assertEquals("Java/" + HystrixTestUtils.class.getName() + "/runCommand", segment.getName());
Assert.assertEquals(1, segment.getCallCount());
List<TraceSegment> children = segment.getChildren();
TraceSegment contexSchedulerActionSegment = null;
switch(type) {
case EXECUTE:
Assert.assertEquals(1, children.size());
segment = children.get(0);
Assert.assertEquals("Java/" + command + "/execute", segment.getName());
Assert.assertEquals(1, segment.getCallCount());
children = segment.getChildren();
Assert.assertEquals(1, children.size());
segment = children.get(0);
// purposely fall through
case QUEUE:
Assert.assertEquals(1, children.size());
segment = children.get(0);
Assert.assertEquals("Java/" + command + "/queue", segment.getName());
Assert.assertEquals(1, segment.getCallCount());
children = segment.getChildren();
// purposely fall through
case TO_OBSERVABLE:
Assert.assertEquals(2, children.size());
segment = children.get(0);
contexSchedulerActionSegment = children.get(1);
Assert.assertEquals("Java/" + command + "/toObservable", segment.getName());
Assert.assertEquals(1, segment.getCallCount());
children = segment.getChildren();
Assert.assertEquals(0, children.size());
Assert.assertEquals("Java/com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction/call", contexSchedulerActionSegment.getName());
Assert.assertEquals(1, contexSchedulerActionSegment.getCallCount());
children = contexSchedulerActionSegment.getChildren();
Assert.assertEquals(1, children.size());
segment = children.get(0);
// JAVA-2383: Subclasses are naming the tx
// Assert.assertEquals("Java/com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction/call", segment.getName());
Assert.assertEquals(1, segment.getCallCount());
children = segment.getChildren();
}
}
use of com.newrelic.agent.introspec.TransactionTrace 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.TransactionTrace in project newrelic-java-agent by newrelic.
the class MetricStateConnectTest method shouldSetMetricOnFirstConnect.
@Test
public void shouldSetMetricOnFirstConnect() throws Exception {
Introspector introspector = InstrumentationTestRunner.getIntrospector();
String transactionName = runTransactionAndIntrospect(introspector, false);
TransactionTrace trace = introspector.getTransactionTracesForTransaction(transactionName).iterator().next();
assertEquals("External/localhost/HttpURLConnection/connect", trace.getInitialTraceSegment().getName());
assertTrue(introspector.getMetricsForTransaction(transactionName).containsKey("External/localhost/HttpURLConnection"));
String defaultMetricName = transactionName.replace("OtherTransaction/Custom", "Java");
assertNotEquals(defaultMetricName, trace.getInitialTraceSegment().getName());
assertFalse(introspector.getMetricsForTransaction(transactionName).containsKey(defaultMetricName));
}
use of com.newrelic.agent.introspec.TransactionTrace in project newrelic-java-agent by newrelic.
the class MetricStateResponseCodeTest method runAndVerifyFirstCall.
private TraceSegment runAndVerifyFirstCall(MetricState target, int nCalls) throws Exception {
Introspector introspector = InstrumentationTestRunner.getIntrospector();
callGetResponseCode(target, nCalls);
// The name of the @Trace(dispatcher = true) method
String transactionName = fetchTransactionName(introspector, "callGetResponseCode");
// We only have one call to this external metric.
assertTrue(introspector.getMetricsForTransaction(transactionName).containsKey("External/localhost/HttpURLConnection"));
assertEquals(1, introspector.getMetricsForTransaction(transactionName).get("External/localhost/HttpURLConnection").getCallCount());
// The number of segments is equal to the number of calls to getResponseCode.
TransactionTrace trace = introspector.getTransactionTracesForTransaction(transactionName).iterator().next();
TraceSegment callGetResponseCodeSegment = trace.getInitialTraceSegment();
assertEquals(nCalls, callGetResponseCodeSegment.getChildren().size());
// Only the first call is named External/.../getResponseCode
TraceSegment renamedSegment = callGetResponseCodeSegment.getChildren().get(0);
assertEquals(1, renamedSegment.getCallCount());
assertEquals("External/localhost/HttpURLConnection/getResponseCode", renamedSegment.getName());
return callGetResponseCodeSegment;
}
Aggregations