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);
}
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"));
}
}
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"));
}
}
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"));
}
}
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"));
}
}
Aggregations