Search in sources :

Example 11 with TransactionTrace

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"));
    });
}
Also used : TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Introspector(com.newrelic.agent.introspec.Introspector) TraceSegment(com.newrelic.agent.introspec.TraceSegment) DatastoreHelper(com.newrelic.agent.introspec.DatastoreHelper) Java10IncompatibleTest(com.newrelic.test.marker.Java10IncompatibleTest) Java13IncompatibleTest(com.newrelic.test.marker.Java13IncompatibleTest) Java16IncompatibleTest(com.newrelic.test.marker.Java16IncompatibleTest) Java9IncompatibleTest(com.newrelic.test.marker.Java9IncompatibleTest) Java17IncompatibleTest(com.newrelic.test.marker.Java17IncompatibleTest) Java14IncompatibleTest(com.newrelic.test.marker.Java14IncompatibleTest) Test(org.junit.Test) Java11IncompatibleTest(com.newrelic.test.marker.Java11IncompatibleTest) Java15IncompatibleTest(com.newrelic.test.marker.Java15IncompatibleTest) Java12IncompatibleTest(com.newrelic.test.marker.Java12IncompatibleTest) Java18IncompatibleTest(com.newrelic.test.marker.Java18IncompatibleTest)

Example 12 with TransactionTrace

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();
    }
}
Also used : TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) TraceSegment(com.newrelic.agent.introspec.TraceSegment)

Example 13 with TransactionTrace

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"));
}
Also used : TransactionEvent(com.newrelic.agent.introspec.TransactionEvent) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Introspector(com.newrelic.agent.introspec.Introspector) TraceSegment(com.newrelic.agent.introspec.TraceSegment)

Example 14 with TransactionTrace

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));
}
Also used : TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Introspector(com.newrelic.agent.introspec.Introspector) Test(org.junit.Test)

Example 15 with TransactionTrace

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;
}
Also used : TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Introspector(com.newrelic.agent.introspec.Introspector) TraceSegment(com.newrelic.agent.introspec.TraceSegment)

Aggregations

TransactionTrace (com.newrelic.agent.introspec.TransactionTrace)33 Test (org.junit.Test)27 TraceSegment (com.newrelic.agent.introspec.TraceSegment)24 Introspector (com.newrelic.agent.introspec.Introspector)23 TransactionEvent (com.newrelic.agent.introspec.TransactionEvent)15 Java16IncompatibleTest (com.newrelic.test.marker.Java16IncompatibleTest)12 Java17IncompatibleTest (com.newrelic.test.marker.Java17IncompatibleTest)12 ExternalRequest (com.newrelic.agent.introspec.ExternalRequest)10 DatastoreHelper (com.newrelic.agent.introspec.DatastoreHelper)7 URI (java.net.URI)7 Java10IncompatibleTest (com.newrelic.test.marker.Java10IncompatibleTest)6 Java11IncompatibleTest (com.newrelic.test.marker.Java11IncompatibleTest)6 Java12IncompatibleTest (com.newrelic.test.marker.Java12IncompatibleTest)6 Java13IncompatibleTest (com.newrelic.test.marker.Java13IncompatibleTest)6 Java14IncompatibleTest (com.newrelic.test.marker.Java14IncompatibleTest)6 Java15IncompatibleTest (com.newrelic.test.marker.Java15IncompatibleTest)6 Java7IncompatibleTest (com.newrelic.test.marker.Java7IncompatibleTest)6 Java9IncompatibleTest (com.newrelic.test.marker.Java9IncompatibleTest)6 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)4 CountDownLatch (java.util.concurrent.CountDownLatch)4