use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class AbstractTracerTest method testAddCustomAttributeCheckLimit.
@Test
public void testAddCustomAttributeCheckLimit() {
// setup
Transaction txn = mock(Transaction.class, RETURNS_DEEP_STUBS);
TransactionActivity txnActivity = mock(TransactionActivity.class);
when(txn.getTransactionCounts().isOverTracerSegmentLimit()).thenReturn(true);
when(txn.getTransactionActivity()).thenReturn(txnActivity);
when(txnActivity.getTransaction()).thenReturn(txn);
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
DefaultTracer target = new OtherRootTracer(txn, sig, this, new SimpleMetricNameFormat("test"));
// execution
target.addCustomAttribute("hamburger", "bun");
target.addCustomAttribute("numToppings", 4);
target.addCustomAttribute("cheese", true);
// assertions
assertNull(target.getCustomAttribute("hamburger"));
assertNull(target.getCustomAttribute("numToppings"));
assertNull(target.getCustomAttribute("cheese"));
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class AbstractTracerTest method createTxnAndTracer.
private AbstractTracer createTxnAndTracer(boolean addChild, boolean childIsTransactionSegment) {
Transaction tx = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
DefaultTracer rootTracer = new OtherRootTracer(tx, sig, this, new SimpleMetricNameFormat("test"));
tx.getTransactionActivity().tracerStarted(rootTracer);
if (addChild) {
ClassMethodSignature sig2 = new ClassMethodSignature(getClass().getName(), "dudechild", "()V");
int flags = DEFAULT_TRACER_FLAGS;
if (childIsTransactionSegment) {
flags |= TRANSACTION_TRACER_SEGMENT;
} else {
flags &= (~TRANSACTION_TRACER_SEGMENT);
}
DefaultTracer childTracer = new DefaultTracer(tx.getTransactionActivity(), sig2, this, new SimpleMetricNameFormat("test"), flags);
childTracer.setParentTracer(rootTracer);
tx.getTransactionActivity().tracerStarted(childTracer);
return childTracer;
}
return rootTracer;
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class DefaultSqlTracerTest method getJSON.
private String getJSON(RecordSql recordSql) {
MockServiceManager serviceManager = new MockServiceManager();
serviceManager.setConfigService(new MockConfigService(AgentConfigFactory.createAgentConfig(Collections.<String, Object>emptyMap(), Collections.<String, Object>emptyMap(), null)));
ServiceManager originalServiceManager = ServiceFactory.getServiceManager();
try {
ServiceFactory.setServiceManager(serviceManager);
Transaction transaction = mock(Transaction.class);
TransactionActivity txa = mock(TransactionActivity.class);
when(transaction.getTransactionActivity()).thenReturn(txa);
when(txa.getTransaction()).thenReturn(transaction);
TransactionTracerConfig ttConfig = mock(TransactionTracerConfig.class);
when(ttConfig.getRecordSql()).thenReturn(recordSql.toString());
when(transaction.getTransactionTracerConfig()).thenReturn(ttConfig);
ClassMethodSignature sig = new ClassMethodSignature("", "", "");
DefaultSqlTracer tracer = new DefaultSqlTracer(transaction, sig, new Object(), new SimpleMetricNameFormat("BoundedConcurrentCacheTest"), TracerFlags.GENERATE_SCOPED_METRIC);
tracer.setRawSql("select * from user where ssn = ?");
tracer.setParams(new Object[] { 666666666 });
Object sqlObject = tracer.getSql();
return sqlObject.toString();
} finally {
ServiceFactory.setServiceManager(originalServiceManager);
}
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class DefaultSqlTracerTest method newTracer.
private DefaultSqlTracer newTracer(String sql) throws SQLException {
DummyConnection conn = new DummyConnection();
Statement statement = conn.createStatement();
Transaction transaction = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
DefaultSqlTracer result = new DefaultSqlTracer(transaction, sig, statement, new SimpleMetricNameFormat(null), DefaultTracer.DEFAULT_TRACER_FLAGS);
result.setRawSql(sql);
// prevent "Inconsistent state! ..." errors
AgentHelper.setLastTracer(result);
return result;
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testNameTx.
@Test
public void testNameTx() {
Transaction tx = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
DefaultTracer parentTracer = new OtherRootTracer(tx, sig, this, new SimpleMetricNameFormat("test"));
tx.getTransactionActivity().tracerStarted(parentTracer);
// the important thing is that we're changing the dispatcher
tx.convertToWebTransaction();
tx.setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, true, "custom", "foo");
assertEquals(0, AgentHelper.getChildren(parentTracer).size());
parentTracer.finish(Opcodes.RETURN, null);
assertEquals("WebTransaction/custom/foo", tx.getPriorityTransactionName().getName());
}
Aggregations