Search in sources :

Example 16 with TransactionTrace

use of com.newrelic.agent.introspec.TransactionTrace in project newrelic-java-agent by newrelic.

the class CassandraTest method testBasic.

@Test
public void testBasic() {
    demoBasic();
    assertEquals(1, InstrumentationTestRunner.getIntrospector().getFinishedTransactionCount(1000));
    Collection<String> transactionNames = InstrumentationTestRunner.getIntrospector().getTransactionNames();
    assertEquals(1, transactionNames.size());
    String txName = transactionNames.iterator().next();
    DatastoreHelper helper = new DatastoreHelper(CASSANDRA_PRODUCT);
    helper.assertScopedStatementMetricCount(txName, "INSERT", "users", 1);
    helper.assertScopedStatementMetricCount(txName, "SELECT", "users", 3);
    helper.assertScopedStatementMetricCount(txName, "UPDATE", "users", 1);
    helper.assertScopedStatementMetricCount(txName, "DELETE", "users", 1);
    helper.assertAggregateMetrics();
    helper.assertUnscopedOperationMetricCount("INSERT", 1);
    helper.assertUnscopedOperationMetricCount("SELECT", 3);
    helper.assertUnscopedOperationMetricCount("UPDATE", 1);
    helper.assertUnscopedOperationMetricCount("DELETE", 1);
    helper.assertUnscopedStatementMetricCount("INSERT", "users", 1);
    helper.assertUnscopedStatementMetricCount("SELECT", "users", 3);
    helper.assertUnscopedStatementMetricCount("UPDATE", "users", 1);
    helper.assertUnscopedStatementMetricCount("DELETE", "users", 1);
    Collection<TransactionTrace> traces = InstrumentationTestRunner.getIntrospector().getTransactionTracesForTransaction(txName);
    assertEquals(1, traces.size());
    TransactionTrace trace = Iterables.getFirst(traces, null);
    assertNotNull(trace);
    assertBasicTraceSegmentAttributes(trace);
}
Also used : TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) DatastoreHelper(com.newrelic.agent.introspec.DatastoreHelper) Java16IncompatibleTest(com.newrelic.test.marker.Java16IncompatibleTest) Java17IncompatibleTest(com.newrelic.test.marker.Java17IncompatibleTest) Test(org.junit.Test) Java7IncompatibleTest(com.newrelic.test.marker.Java7IncompatibleTest)

Example 17 with TransactionTrace

use of com.newrelic.agent.introspec.TransactionTrace in project newrelic-java-agent by newrelic.

the class TransactionTraceTest method testOneTracerInTransaction.

@Test
public void testOneTracerInTransaction() {
    // transaction
    long start = System.currentTimeMillis();
    Transaction.getTransaction();
    Tracer rootTracer = IntrospectorImplTest.createOtherTracer("rootOnly");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
    rootTracer.finish(Opcodes.RETURN, 0);
    long end = System.currentTimeMillis();
    // data check
    Map<String, TracedMetricData> metrics = impl.getUnscopedMetrics();
    TracedMetricData txMetric = metrics.get("OtherTransaction/rootOnly");
    Collection<TransactionTrace> traces = impl.getTransactionTracesForTransaction("OtherTransaction/rootOnly");
    Assert.assertEquals(1, traces.size());
    TransactionTrace trace = traces.iterator().next();
    Assert.assertEquals(txMetric.getTotalTimeInSec(), trace.getResponseTimeInSec(), .01);
    Assert.assertEquals(trace.getWallClockDurationInSec(), trace.getResponseTimeInSec(), .01);
    Assert.assertTrue(trace.getStartTime() >= start);
    Assert.assertTrue(trace.getStartTime() <= end);
    TraceSegment segment = trace.getInitialTraceSegment();
    Assert.assertEquals(0, segment.getChildren().size());
    Map<String, Object> info = segment.getTracerAttributes();
    Assert.assertNotNull(info.get("async_context"));
    Assert.assertNotNull(info.get("exclusive_duration_millis"));
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) Tracer(com.newrelic.agent.tracers.Tracer) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) TraceSegment(com.newrelic.agent.introspec.TraceSegment) Test(org.junit.Test)

Example 18 with TransactionTrace

use of com.newrelic.agent.introspec.TransactionTrace in project newrelic-java-agent by newrelic.

the class TransactionTraceTest method testOneTracerInTransactionWithChildren.

@Test
public void testOneTracerInTransactionWithChildren() {
    // transaction
    long start = System.currentTimeMillis();
    Transaction.getTransaction();
    Tracer rootTracer = IntrospectorImplTest.createOtherTracer("rootOnly");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(rootTracer);
    Tracer child1 = IntrospectorImplTest.createDefaultTracer("default1");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child1);
    child1.finish(Opcodes.RETURN, 0);
    Tracer child2 = IntrospectorImplTest.createDefaultTracer("default2");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child2);
    child2.finish(Opcodes.RETURN, 0);
    Tracer child3 = IntrospectorImplTest.createDefaultTracer("default3");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child3);
    child3.setAgentAttribute("myatt", "hello");
    child3.setAgentAttribute("myNumber", 99);
    child3.finish(Opcodes.RETURN, 0);
    rootTracer.finish(Opcodes.RETURN, 0);
    long end = System.currentTimeMillis();
    // data check
    Assert.assertEquals(1, impl.getFinishedTransactionCount());
    Map<String, TracedMetricData> metrics = impl.getUnscopedMetrics();
    TracedMetricData txMetric = metrics.get("OtherTransaction/rootOnly");
    Collection<TransactionTrace> traces = impl.getTransactionTracesForTransaction("OtherTransaction/rootOnly");
    Assert.assertEquals(1, traces.size());
    TransactionTrace trace = traces.iterator().next();
    Assert.assertEquals(txMetric.getTotalTimeInSec(), trace.getResponseTimeInSec(), .01);
    Assert.assertEquals(trace.getWallClockDurationInSec(), trace.getResponseTimeInSec(), .01);
    Assert.assertTrue(trace.getStartTime() >= start);
    Assert.assertTrue(trace.getStartTime() <= end);
    TraceSegment segment = trace.getInitialTraceSegment();
    Assert.assertEquals(3, segment.getChildren().size());
    long relativeStart = segment.getRelativeStartTime();
    long relativeEnd = segment.getRelativeEndTime();
    for (TraceSegment current : segment.getChildren()) {
        Map<String, Object> info = current.getTracerAttributes();
        Assert.assertNull(info.get("async_context"));
        Assert.assertNotNull(info.get("exclusive_duration_millis"));
        Assert.assertEquals(0, current.getChildren().size());
        Assert.assertTrue(current.getMethodName().startsWith("default"));
        Assert.assertTrue(current.getName().startsWith("Custom/default"));
        Assert.assertTrue(current.getRelativeStartTime() >= relativeStart);
        Assert.assertTrue(current.getRelativeEndTime() <= relativeEnd);
        Assert.assertTrue(current.getRelativeStartTime() <= current.getRelativeEndTime());
        Assert.assertEquals("MyClass", current.getClassName());
        if (current.getName().equals("Custom/default3")) {
            Assert.assertEquals("hello", info.get("myatt"));
            Assert.assertEquals(99, info.get("myNumber"));
        }
    }
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) Tracer(com.newrelic.agent.tracers.Tracer) TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) TraceSegment(com.newrelic.agent.introspec.TraceSegment) Test(org.junit.Test)

Example 19 with TransactionTrace

use of com.newrelic.agent.introspec.TransactionTrace in project newrelic-java-agent by newrelic.

the class DynamoApiTest method testAsyncParenting.

@Test
public void testAsyncParenting() throws ExecutionException, InterruptedException {
    batchGetAsyncTxn();
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    assertEquals(1, introspector.getFinishedTransactionCount(10000));
    String txName = introspector.getTransactionNames().iterator().next();
    TransactionTrace trace = introspector.getTransactionTracesForTransaction(txName).iterator().next();
    TraceSegment initialTraceSegment = trace.getInitialTraceSegment();
    assertEquals("batchGetAsyncTxn", initialTraceSegment.getMethodName());
    assertEquals("batchGetItemAsync", initialTraceSegment.getChildren().get(0).getMethodName());
}
Also used : TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Introspector(com.newrelic.agent.introspec.Introspector) TraceSegment(com.newrelic.agent.introspec.TraceSegment) Test(org.junit.Test)

Example 20 with TransactionTrace

use of com.newrelic.agent.introspec.TransactionTrace in project newrelic-java-agent by newrelic.

the class MetricStateConnectTest method shouldNotSetMetricOnSecondConnect.

@Test
public void shouldNotSetMetricOnSecondConnect() throws Exception {
    Introspector introspector = InstrumentationTestRunner.getIntrospector();
    String transactionName = runTransactionAndIntrospect(introspector, true);
    TransactionTrace trace = introspector.getTransactionTracesForTransaction(transactionName).iterator().next();
    assertNotEquals("External/localhost/HttpURLConnection/connect", trace.getInitialTraceSegment().getName());
    assertFalse(introspector.getMetricsForTransaction(transactionName).containsKey("External/localhost/HttpURLConnection"));
    String defaultMetricName = transactionName.replace("OtherTransaction/Custom", "Java");
    assertEquals(defaultMetricName, trace.getInitialTraceSegment().getName());
    assertTrue(introspector.getMetricsForTransaction(transactionName).containsKey(defaultMetricName));
}
Also used : TransactionTrace(com.newrelic.agent.introspec.TransactionTrace) Introspector(com.newrelic.agent.introspec.Introspector) Test(org.junit.Test)

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