use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.
the class TransactionTest method testTracerLimit2.
@SuppressWarnings("unchecked")
@Test
public void testTracerLimit2() throws Exception {
Map<String, Object> config = createConfigMap();
Map<String, Object> ttmap = (Map) config.get(AgentConfigImpl.TRANSACTION_TRACER);
ttmap.put("segment_limit", 3);
createServiceManager(config);
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
tx.getTransactionActivity().tracerStarted(rootTracer);
DefaultTracer t1 = createBasicTracer("one");
tx.getTransactionActivity().tracerStarted(t1);
tx.getTransactionActivity().tracerFinished(t1, 0);
DefaultTracer t2 = createBasicTracer("two");
tx.getTransactionActivity().tracerStarted(t2);
tx.getTransactionActivity().tracerFinished(t2, 0);
DefaultTracer t3 = createBasicTracer("three");
tx.getTransactionActivity().tracerStarted(t3);
tx.getTransactionActivity().tracerFinished(t3, 0);
DefaultTracer t4 = createBasicTracer("four");
tx.getTransactionActivity().tracerStarted(t4);
tx.getTransactionActivity().tracerFinished(t4, 0);
DefaultTracer t5 = createBasicTracer("five");
tx.getTransactionActivity().tracerStarted(t5);
tx.getTransactionActivity().tracerFinished(t5, 0);
finishTransaction(tx, rootTracer);
Set<TransactionActivity> done = tx.getFinishedChildren();
assertEquals(1, done.size());
TransactionActivity txa = done.iterator().next();
List<Tracer> tracers = txa.getTracers();
assertEquals(3, tracers.size());
assertTrue(tracers.contains(t1));
assertTrue(tracers.contains(t2));
assertTrue(tracers.contains(t3));
}
use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.
the class TransactionTest method noticeThenSetAsAPIUsesCurrentSpan.
@Test
public void noticeThenSetAsAPIUsesCurrentSpan() throws Exception {
createServiceManager(Collections.<String, Object>emptyMap());
Transaction.clearTransaction();
Tracer dispatcherTracer = createDispatcherTracer(true);
Transaction tx = dispatcherTracer.getTransactionActivity().getTransaction();
tx.getTransactionActivity().tracerStarted(dispatcherTracer);
Throwable exc = new Throwable();
tx.noticeTracerException(exc, "span id 1");
tx.noticeTracerException(exc, "span id 2");
tx.setThrowable(exc, TransactionErrorPriority.API, false);
assertEquals(dispatcherTracer.getGuid(), tx.getThrowable().spanId);
}
use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.
the class TransactionTest method testSampleFlag.
@Test
public void testSampleFlag() throws Exception {
Map<String, Object> configMap = createNRDTConfigMap(false);
createServiceManager(configMap);
serviceManager.setDistributedTraceService(mockDistributedTraceService);
Transaction.clearTransaction();
Tracer dispatcherTracer = createDispatcherTracer(true);
Transaction transaction = dispatcherTracer.getTransactionActivity().getTransaction();
transaction.getTransactionActivity().tracerStarted(dispatcherTracer);
String inboundPayload = "{" + " \"v\": [0,2]," + " \"d\": {" + " \"ty\": \"Mobile\"," + " \"ac\": \"9123\"," + " \"tk\": \"67890\"," + " \"ap\": \"51424\"" + " \"id\": \"27856f70d3d314b7\"," + " \"tr\": \"3221bf09aa0bcf0d\"," + " \"pr\": 0.0002," + " \"ti\": 1482959525577," + " }" + "}";
transaction.acceptDistributedTracePayload(inboundPayload);
dispatcherTracer.finish(Opcodes.ARETURN, null);
assertEquals(0.0002f, transaction.getPriority(), 0.0f);
Transaction.clearTransaction();
dispatcherTracer = createDispatcherTracer(true);
transaction = dispatcherTracer.getTransactionActivity().getTransaction();
transaction.getTransactionActivity().tracerStarted(dispatcherTracer);
inboundPayload = "{" + " \"v\": [0,2]," + " \"d\": {" + " \"ty\": \"Mobile\"," + " \"ac\": \"9123\"," + " \"tk\": \"67890\"," + " \"ap\": \"51424\"" + " \"id\": \"27856f70d3d314b7\"," + " \"tr\": \"3221bf09aa0bcf0d\"," + " \"pr\": 1.348272," + " \"ti\": 1482959525577" + " }" + "}";
transaction.acceptDistributedTracePayload(inboundPayload);
dispatcherTracer.finish(Opcodes.ARETURN, null);
assertTrue(DistributedTraceUtil.isSampledPriority(transaction.getPriority()));
}
use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.
the class TransactionTest method testSupportabilityCreateBeforeAccept.
@Test
public void testSupportabilityCreateBeforeAccept() throws Exception {
Map<String, Object> configMap = createNRDTConfigMap(false);
createServiceManager(configMap);
final CountDownLatch latch = new CountDownLatch(1);
final SimpleStatsEngine unscopedStats = new SimpleStatsEngine();
ServiceFactory.getTransactionService().addTransactionListener(new TransactionListener() {
@Override
public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
if (transactionData.getPriorityTransactionName().getName().equals("WebTransaction/Test/createBeforeAcceptTxn")) {
unscopedStats.mergeStats(transactionStats.getUnscopedStats());
latch.countDown();
}
}
});
Transaction.clearTransaction();
Tracer dispatcherTracer = createDispatcherTracer(true);
Transaction transaction = dispatcherTracer.getTransactionActivity().getTransaction();
transaction.getTransactionActivity().tracerStarted(dispatcherTracer);
transaction.setTransactionName(com.newrelic.api.agent.TransactionNamePriority.CUSTOM_HIGH, true, "Test", "createBeforeAcceptTxn");
transaction.createDistributedTracePayload("spanId31238ou");
String inboundPayload = "{" + " \"v\": [0,2]," + " \"d\": {" + " \"ty\": \"Mobile\"," + " \"ac\": \"9123\"," + " \"tk\": \"67890\"," + " \"ap\": \"51424\"" + " \"id\": \"27856f70d3d314b7\"," + " \"tr\": \"3221bf09aa0bcf0d\"," + " \"pr\": 0.00001," + " \"ti\": 1482959525577" + " }" + "}";
transaction.acceptDistributedTracePayload(inboundPayload);
dispatcherTracer.finish(Opcodes.ARETURN, null);
latch.await();
assertTrue(1 <= transaction.getTransactionActivity().getTransactionStats().getUnscopedStats().getStats(MetricNames.SUPPORTABILITY_ACCEPT_PAYLOAD_CREATE_BEFORE_ACCEPT).getCallCount());
}
use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.
the class SegmentTest method makeTransaction.
/**
* Creates a transaction with one tracer and returns the root tracer (unfinished).
*/
private static Tracer makeTransaction() {
Transaction tx = Transaction.getTransaction(true);
TransactionActivity txa = TransactionActivity.get();
Assert.assertNotNull(txa);
Tracer root = new OtherRootTracer(tx, new ClassMethodSignature("com.newrelic.agent.SegmentTest", "makeTransaction", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
txa.tracerStarted(root);
tx.setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, true, "FOO", "BAR", "BAZ");
return root;
}
Aggregations