Search in sources :

Example 6 with TraceSegment

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

the class TransactionTraceTest method testOneTracerInTransactionWithDepthChildren.

@Test
public void testOneTracerInTransactionWithDepthChildren() {
    // 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);
    Tracer child2 = IntrospectorImplTest.createDefaultTracer("default2");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child2);
    Tracer child3 = IntrospectorImplTest.createDefaultTracer("default3");
    Transaction.getTransaction().getTransactionActivity().tracerStarted(child3);
    child3.setAgentAttribute("myatt", "hello");
    child3.setAgentAttribute("myNumber", 99);
    child3.finish(Opcodes.RETURN, 0);
    child2.finish(Opcodes.RETURN, 0);
    child1.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(1, segment.getChildren().size());
    TraceSegment seg = segment.getChildren().get(0);
    long relativeStart = segment.getRelativeStartTime();
    long relativeEnd = segment.getRelativeEndTime();
    int count = 0;
    while (seg != null) {
        count++;
        Assert.assertTrue(seg.getRelativeStartTime() >= relativeStart);
        Assert.assertTrue(seg.getRelativeEndTime() <= relativeEnd);
        Assert.assertTrue(seg.getRelativeStartTime() <= seg.getRelativeEndTime());
        relativeStart = seg.getRelativeStartTime();
        relativeEnd = seg.getRelativeEndTime();
        Map<String, Object> info = seg.getTracerAttributes();
        Assert.assertNull(info.get("async_context"));
        Assert.assertNotNull(info.get("exclusive_duration_millis"));
        Assert.assertTrue(seg.getMethodName().startsWith("default"));
        Assert.assertTrue(seg.getName().startsWith("Custom/default"));
        Assert.assertEquals("MyClass", seg.getClassName());
        if (seg.getName().equals("Custom/default3")) {
            Assert.assertEquals("hello", info.get("myatt"));
            Assert.assertEquals(99, info.get("myNumber"));
            Assert.assertEquals(0, seg.getChildren().size());
            seg = null;
        } else {
            Assert.assertEquals(1, seg.getChildren().size());
            seg = seg.getChildren().get(0);
        }
    }
    Assert.assertEquals(3, count);
}
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 7 with TraceSegment

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

the class CassandraTest method assertListenerTraceSegmentAttributes.

private void assertListenerTraceSegmentAttributes(TransactionTrace trace) {
    List<TraceSegment> children = trace.getInitialTraceSegment().getChildren();
    assertEquals(1, children.size());
    for (TraceSegment child : children) {
        Map<String, Object> tracerAttributes = child.getTracerAttributes();
        assertEquals(hostName, tracerAttributes.get("host"));
        assertEquals(String.valueOf(port), tracerAttributes.get("port_path_or_id"));
        assertEquals(databaseName, tracerAttributes.get("db.instance"));
    }
}
Also used : TraceSegment(com.newrelic.agent.introspec.TraceSegment)

Example 8 with TraceSegment

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

the class CassandraTest method assertCancelFutureTraceSegmentAttributes.

private void assertCancelFutureTraceSegmentAttributes(TransactionTrace trace) {
    List<TraceSegment> children = trace.getInitialTraceSegment().getChildren();
    assertEquals(1, children.size());
    for (TraceSegment child : children) {
        Map<String, Object> tracerAttributes = child.getTracerAttributes();
        assertNull(tracerAttributes.get("host"));
        assertNull(tracerAttributes.get("port_path_or_id"));
        assertEquals(databaseName, tracerAttributes.get("db.instance"));
    }
}
Also used : TraceSegment(com.newrelic.agent.introspec.TraceSegment)

Example 9 with TraceSegment

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

the class CassandraTest method assertBasicTraceSegmentAttributes.

private void assertBasicTraceSegmentAttributes(TransactionTrace trace) {
    List<TraceSegment> children = trace.getInitialTraceSegment().getChildren();
    assertEquals(6, children.size());
    for (TraceSegment child : children) {
        Map<String, Object> tracerAttributes = child.getTracerAttributes();
        assertEquals(hostName, tracerAttributes.get("host"));
        assertEquals(String.valueOf(port), tracerAttributes.get("port_path_or_id"));
        assertEquals(databaseName, tracerAttributes.get("db.instance"));
    }
}
Also used : TraceSegment(com.newrelic.agent.introspec.TraceSegment)

Example 10 with TraceSegment

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

the class CassandraTest method assertBatchStatementInsideSimpleStatementTraceSegmentAttributes.

private void assertBatchStatementInsideSimpleStatementTraceSegmentAttributes(TransactionTrace trace) {
    List<TraceSegment> children = trace.getInitialTraceSegment().getChildren();
    assertEquals(1, children.size());
    for (TraceSegment child : children) {
        Map<String, Object> tracerAttributes = child.getTracerAttributes();
        assertEquals(hostName, tracerAttributes.get("host"));
        assertEquals(String.valueOf(port), tracerAttributes.get("port_path_or_id"));
        assertEquals(databaseName, tracerAttributes.get("db.instance"));
    }
}
Also used : TraceSegment(com.newrelic.agent.introspec.TraceSegment)

Aggregations

TraceSegment (com.newrelic.agent.introspec.TraceSegment)33 TransactionTrace (com.newrelic.agent.introspec.TransactionTrace)24 Introspector (com.newrelic.agent.introspec.Introspector)19 Test (org.junit.Test)19 TransactionEvent (com.newrelic.agent.introspec.TransactionEvent)14 ExternalRequest (com.newrelic.agent.introspec.ExternalRequest)10 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 Java16IncompatibleTest (com.newrelic.test.marker.Java16IncompatibleTest)6 Java17IncompatibleTest (com.newrelic.test.marker.Java17IncompatibleTest)6 Java9IncompatibleTest (com.newrelic.test.marker.Java9IncompatibleTest)6 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)3 Tracer (com.newrelic.agent.tracers.Tracer)3