use of com.newrelic.agent.introspec.TraceSegment in project newrelic-java-agent by newrelic.
the class CassandraTest method assertBatchStatementTraceSegmentAttributes.
private void assertBatchStatementTraceSegmentAttributes(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 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"));
}
use of com.newrelic.agent.introspec.TraceSegment 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"));
}
}
}
use of com.newrelic.agent.introspec.TraceSegment 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());
}
use of com.newrelic.agent.introspec.TraceSegment in project newrelic-java-agent by newrelic.
the class MetricStateResponseCodeTest method shouldBumpMetricOnceIfAlreadyHaveInputStream.
/**
* Objective: Calling getInputStream, then getResponseCode, only records the external metric once, and
* only has one External/ segment. The second segment is Custom/.
*/
@Test
public void shouldBumpMetricOnceIfAlreadyHaveInputStream() throws Exception {
Introspector introspector = InstrumentationTestRunner.getIntrospector();
MetricState target = new MetricState();
callGetInputStreamThenResponseCode(target);
// Only one external call.
String transactionName = fetchTransactionName(introspector, "callGetInputStreamThenResponseCode");
assertTrue(introspector.getMetricsForTransaction(transactionName).containsKey("External/localhost/HttpURLConnection"));
assertEquals(1, introspector.getMetricsForTransaction(transactionName).get("External/localhost/HttpURLConnection").getCallCount());
// Two child segments within the transaction.
TransactionTrace trace = introspector.getTransactionTracesForTransaction(transactionName).iterator().next();
TraceSegment traceSegment = trace.getInitialTraceSegment();
assertEquals(2, traceSegment.getChildren().size());
// The first segment is external.
TraceSegment renamedSegment = traceSegment.getChildren().get(0);
assertEquals(1, renamedSegment.getCallCount());
assertEquals("External/localhost/HttpURLConnection/getInputStream", renamedSegment.getName());
// The second is a normal method call.
TraceSegment defaultName = traceSegment.getChildren().get(1);
assertEquals(1, defaultName.getCallCount());
assertEquals("Custom/" + this.getClass().getName() + "/simulatedInstrumentedGetResponseCodeMethod", defaultName.getName());
}
Aggregations