Search in sources :

Example 61 with SimpleMetricNameFormat

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"));
}
Also used : Transaction(com.newrelic.agent.Transaction) TransactionActivity(com.newrelic.agent.TransactionActivity) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) Test(org.junit.Test)

Example 62 with SimpleMetricNameFormat

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;
}
Also used : Transaction(com.newrelic.agent.Transaction) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 63 with SimpleMetricNameFormat

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);
    }
}
Also used : ServiceManager(com.newrelic.agent.service.ServiceManager) JSONObject(org.json.simple.JSONObject) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 64 with SimpleMetricNameFormat

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;
}
Also used : Statement(java.sql.Statement) DummyConnection(sql.DummyConnection) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 65 with SimpleMetricNameFormat

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());
}
Also used : Transaction(com.newrelic.agent.Transaction) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) Test(org.junit.Test)

Aggregations

SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)70 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)46 Transaction (com.newrelic.agent.Transaction)43 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)34 Test (org.junit.Test)32 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)20 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)17 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)11 Response (com.newrelic.api.agent.Response)10 Tracer (com.newrelic.agent.tracers.Tracer)9 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)9 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)8 Request (com.newrelic.api.agent.Request)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)8 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)8 MockHttpServletResponse (org.apache.struts.mock.MockHttpServletResponse)8 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)7 TransactionDataList (com.newrelic.agent.TransactionDataList)6