use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.
the class ApiTest method testSetRequestAndResponseThenSetTxName.
@Test
public void testSetRequestAndResponseThenSetTxName() {
TransactionDataList txList = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txList);
Transaction tx = Transaction.getTransaction();
OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("blah"));
Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
Request request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
Response response = new ApiTestHelper.ResponseWrapper(new MockHttpServletResponse());
NewRelic.setRequestAndResponse(request, response);
NewRelic.setTransactionName("Test", "Foo");
tracer.finish(0, null);
Assert.assertEquals("WebTransaction/Test/Foo", tx.getPriorityTransactionName().getName());
}
use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.
the class ApiTest method nameTransactionThenSetRequestAndResponse.
@Test
public void nameTransactionThenSetRequestAndResponse() {
TransactionDataList txList = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txList);
Transaction tx = Transaction.getTransaction();
OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("blah"));
Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
tracer.nameTransaction(TransactionNamePriority.CUSTOM_HIGH);
Request request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
Response response = new ApiTestHelper.ResponseWrapper(new MockHttpServletResponse());
NewRelic.setRequestAndResponse(request, response);
tracer.finish(0, null);
Assert.assertEquals("WebTransaction/Custom/test.newrelic.test.agent.api.ApiTest/", tx.getPriorityTransactionName().getName());
}
use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.
the class SpanParentTest method testErrorAttributes.
@Test
public void testErrorAttributes() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("all_enabled_test");
Header actualHeader = txnStarter(true);
try {
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(1, transactionList.size());
Collection<Tracer> tracers = transactionList.get(0).getTracers();
Tracer tracer = ((TracerList) tracers).get(0);
String expectedGuid = tracer.getGuid();
String actualGuid = findGuid(actualHeader.getValue());
Assert.assertEquals(expectedGuid, actualGuid);
ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
List<TracedError> tracedErrors = errorService.getAndClearTracedErrors();
assertEquals(1, tracedErrors.size());
TracedError errorTrace = tracedErrors.get(0);
Map<String, ?> errorAtts = errorTrace.getIntrinsicAtts();
Assert.assertNotNull(errorAtts.get("traceId"));
Assert.assertNotNull(errorAtts.get("guid"));
Assert.assertNotNull(errorAtts.get("priority"));
Assert.assertNotNull(errorAtts.get("sampled"));
} finally {
holder.close();
}
}
use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.
the class SpanParentTest method testCrossProcessOnly.
@Test
public void testCrossProcessOnly() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("cross_process_only_test");
executeCrossProcessOnlyTest();
try {
TransactionDataList transactionList = holder.getTransactionList();
assertEquals(2, transactionList.size());
TransactionData tx1 = transactionList.get(0);
TransactionData tx2 = transactionList.get(1);
Collection<Tracer> tracers1 = tx1.getTracers();
// Only a "rootTracer" on this transaction (root tracer is not in this list)
assertEquals(0, tracers1.size());
Collection<Tracer> tracers2 = tx2.getTracers();
// 1 "rootTracer" (not in this list) + 2 non-external/datastore tracers + 2 external datastore tracers
assertEquals(4, tracers2.size());
SpanEventsService spanEventsService = ServiceFactory.getServiceManager().getSpanEventsService();
String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
SamplingPriorityQueue<SpanEvent> spanEventsPool = spanEventsService.getOrCreateDistributedSamplingReservoir(appName);
assertNotNull(spanEventsPool);
List<SpanEvent> spanEvents = spanEventsPool.asList();
spanEventsPool.clear();
assertNotNull(spanEvents);
assertEquals(2, spanEvents.size());
SpanEvent externalSpanEvent = null;
SpanEvent datastoreSpanEvent = null;
for (SpanEvent spanEvent : spanEvents) {
if (spanEvent.getCategory() == SpanCategory.http) {
externalSpanEvent = spanEvent;
} else if (spanEvent.getCategory() == SpanCategory.datastore) {
datastoreSpanEvent = spanEvent;
}
}
assertNotNull(externalSpanEvent);
assertNotNull(datastoreSpanEvent);
// For right now, we are putting cross-process only mode on ice. Poor orphan spans :(
assertNull(externalSpanEvent.getParentId());
assertNull(datastoreSpanEvent.getParentId());
} finally {
holder.close();
}
}
use of com.newrelic.agent.TransactionDataList in project newrelic-java-agent by newrelic.
the class PreparedStatementSqlTest method sql.
@Test
public void sql() throws Exception {
final String originalSql = "select * from test where name = ?";
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
try {
new StubServlet("dude") {
private static final long serialVersionUID = 1L;
@Override
protected void run(HttpServletRequest request, HttpServletResponse response) throws Exception {
Connection connection = DatabaseHelper.getConnection();
PreparedStatement statement = connection.prepareStatement(originalSql);
statement.setString(1, "test");
statement.executeQuery();
}
};
} catch (Exception e) {
// ignore
}
Assert.assertEquals(2, txs.size());
TransactionData transactionData = txs.get(1);
String actualSql = null;
for (Tracer tracer : AgentHelper.getTracers(transactionData.getRootTracer())) {
if (tracer instanceof SqlTracer) {
actualSql = ((SqlTracer) tracer).getSql().toString();
}
}
Assert.assertNotNull(actualSql);
Assert.assertEquals("select * from test where name = 'test'", actualSql);
}
Aggregations