use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class TransactionTest method recordCpuAndGCTime.
@Test
public void recordCpuAndGCTime() throws Exception {
Map<String, Object> configMap = createConfigMap();
createServiceManager(configMap);
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
Thread.sleep(40);
tx.getTransactionActivity().tracerStarted(rootTracer);
rootTracer.finish(Opcodes.ARETURN, null);
tx.recordFinalGCTime(tx.getTransactionActivity().getTransactionStats());
Long cpuTime = (Long) tx.getIntrinsicAttributes().get(AttributeNames.CPU_TIME_PARAMETER_NAME);
assertNotNull(cpuTime);
assertTrue(cpuTime > 0);
tx.recordFinalGCTime(tx.getTransactionActivity().getTransactionStats());
Long cpuTime2 = (Long) tx.getIntrinsicAttributes().get(AttributeNames.CPU_TIME_PARAMETER_NAME);
assertEquals(cpuTime, cpuTime2);
}
use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class TransactionTest method testTracerLimitAsync.
@SuppressWarnings("unchecked")
@Test
public void testTracerLimitAsync() throws Exception {
Map<String, Object> config = createConfigMap();
Map<String, Object> ttmap = (Map) config.get(AgentConfigImpl.TRANSACTION_TRACER);
ttmap.put("segment_limit", 3);
createServiceManager(config);
Object context1 = 1L;
Object context2 = 2L;
Object context3 = 3L;
Object context4 = 4L;
Object context5 = 5L;
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
BasicRequestRootTracer rootTracer = (BasicRequestRootTracer) createDispatcherTracer(true);
tx.getTransactionActivity().tracerStarted(rootTracer);
assertTrue(ServiceFactory.getAsyncTxService().registerAsyncActivity(context1));
InitThread async1 = new InitThread(context1, context2, false);
async1.start();
async1.join();
assertEquals(1, tx.getFinishedChildren().size());
assertEquals(1, tx.getRunningTransactionActivityCount());
InitThread async2 = new InitThread(context2, context3, false);
async2.start();
async2.join();
assertEquals(2, tx.getFinishedChildren().size());
assertEquals(1, tx.getRunningTransactionActivityCount());
InitThread async3 = new InitThread(context3, context4, false);
async3.start();
async3.join();
assertEquals(3, tx.getFinishedChildren().size());
assertEquals(1, tx.getRunningTransactionActivityCount());
TransactionStats stats = tx.getOverLimitTxStatsforTesting();
assertNull(stats);
InitThread async4 = new InitThread(context4, context5, false);
async4.start();
async4.join();
assertEquals(3, tx.getFinishedChildren().size());
assertEquals(1, tx.getRunningTransactionActivityCount());
stats = tx.getOverLimitTxStatsforTesting();
assertNotNull(stats);
ResponseTimeStatsImpl theStat = (ResponseTimeStatsImpl) stats.getScopedStats().getStatsMap().get("Java/com.newrelic.agent.TransactionTest/dude");
assertNotNull(theStat);
float initValue = theStat.getTotal();
assertEquals(1, theStat.getCallCount());
InitThread async5 = new InitThread(context5, null, false);
async5.start();
async5.join();
assertEquals(3, tx.getFinishedChildren().size());
assertEquals(1, tx.getRunningTransactionActivityCount());
stats = tx.getOverLimitTxStatsforTesting();
assertNotNull(stats);
theStat = (ResponseTimeStatsImpl) stats.getScopedStats().getStatsMap().get("Java/com.newrelic.agent.TransactionTest/dude");
assertNotNull(theStat);
assertTrue(theStat.getTotal() > initValue);
assertEquals(2, theStat.getCallCount());
finishTransaction(tx, rootTracer);
assertEquals(4, tx.getFinishedChildren().size());
assertEquals(0, tx.getRunningTransactionActivityCount());
// here all of the stats should have been merged in - not just the TXAs that were dropped
stats = tx.getOverLimitTxStatsforTesting();
assertNotNull(stats);
theStat = (ResponseTimeStatsImpl) stats.getScopedStats().getStatsMap().get("Java/com.newrelic.agent.TransactionTest/dude");
assertNotNull(theStat);
assertTrue(theStat.getTotal() > initValue);
assertEquals(5, theStat.getCallCount());
}
use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class AgentAttributeSenderTest method testCustomAttributesInTransaction.
@Test
public void testCustomAttributesInTransaction() {
try {
Map<String, Object> settings = new HashMap<>();
settings.put("app_name", APP_NAME);
manager.setConfigService(new ConfigServiceFactory().createConfigServiceUsingSettings(settings));
manager.setTransactionService(new TransactionService());
manager.setTransactionTraceService(new TransactionTraceService());
manager.setAttributesService(new AttributesService());
Transaction t = Transaction.getTransaction();
BasicRequestRootTracer tracer = createDispatcherTracer();
t.getTransactionActivity().tracerStarted(tracer);
NewRelicApiImplementation impl = new NewRelicApiImplementation();
impl.addCustomParameter("abc.thread", "1");
impl.addCustomParameter("request.many", "1");
impl.addCustomParameter("message.many", "1");
impl.addCustomParameter("message.bool", true);
Map<String, Object> customParamMap = new HashMap<>();
customParamMap.put("key1", "val1");
customParamMap.put("key2", 2);
customParamMap.put("key3", new HashMap<>());
customParamMap.put("key4", true);
customParamMap.put("key5", null);
impl.addCustomParameters(customParamMap);
Set<String> expected = Sets.newHashSet("abc.thread", "request.many", "message.many", "key1", "key2", "key4", "message.bool");
verifyOutput(t.getUserAttributes(), expected);
} finally {
Transaction.clearTransaction();
}
}
use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class AgentAttributeSenderTest method createDispatcherTracer.
private BasicRequestRootTracer createDispatcherTracer() {
Transaction tx = Transaction.getTransaction();
MockHttpRequest httpRequest = new MockHttpRequest();
MockHttpResponse httpResponse = new MockHttpResponse();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
return new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
}
use of com.newrelic.agent.tracers.servlet.BasicRequestRootTracer in project newrelic-java-agent by newrelic.
the class AgentAttributeSenderTest method shouldTruncateLongAttributeValues.
@Test
public void shouldTruncateLongAttributeValues() {
try {
Map<String, Object> settings = new HashMap<>();
settings.put("app_name", APP_NAME);
manager.setConfigService(new ConfigServiceFactory().createConfigServiceUsingSettings(settings));
manager.setTransactionService(new TransactionService());
manager.setTransactionTraceService(new TransactionTraceService());
manager.setAttributesService(new AttributesService());
Transaction t = Transaction.getTransaction();
BasicRequestRootTracer tracer = createDispatcherTracer();
t.getTransactionActivity().tracerStarted(tracer);
NewRelicApiImplementation impl = new NewRelicApiImplementation();
impl.addCustomParameter(makeLongString("ignored-key-too-long"), "vv");
String valueVeryLong = makeLongString("v2");
impl.addCustomParameter("truncated-single-value", valueVeryLong);
Map<String, Object> customParamMap = new HashMap<>();
customParamMap.put(makeLongString("ignored-key-too-long-also"), "vx");
customParamMap.put("truncated-map-value", makeLongString("v4"));
impl.addCustomParameters(customParamMap);
Set<String> expected = Sets.newHashSet("truncated-single-value", "truncated-map-value");
Map<String, Object> attribs = t.getUserAttributes();
Assert.assertEquals(expected, attribs.keySet());
Assert.assertEquals(255, attribs.get("truncated-single-value").toString().length());
Assert.assertNotEquals(255, valueVeryLong.length());
Assert.assertEquals(255, attribs.get("truncated-map-value").toString().length());
Assert.assertNotEquals(255, customParamMap.get("truncated-map-value"));
} finally {
Transaction.clearTransaction();
}
}
Aggregations