Search in sources :

Example 46 with ClassMethodSignature

use of com.newrelic.agent.tracers.ClassMethodSignature in project newrelic-java-agent by newrelic.

the class DatabaseServiceTest method instanceLocalhostReplace.

@Test
public void instanceLocalhostReplace() throws Exception {
    Map<String, Object> configMap = createStagingMap();
    Map<String, Object> dsConfigMap = createMap();
    dsConfigMap.put(DatastoreConfigImpl.INSTANCE_REPORTING, true);
    configMap.put(AgentConfigImpl.DATASTORE_TRACER, dsConfigMap);
    createServiceManager(configMap);
    final Connection connection = Mockito.mock(Connection.class);
    DatastoreInstanceDetection.detectConnectionAddress();
    DatastoreInstanceDetection.associateAddress(connection, new InetSocketAddress("localhost", 8080));
    DatastoreInstanceDetection.stopDetectingConnectionAddress();
    Transaction transaction = Transaction.getTransaction(true);
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    TestDefaultSqlTracer tracer = new TestDefaultSqlTracer(transaction, sig, null, new SimpleMetricNameFormat(null), DefaultTracer.DEFAULT_TRACER_FLAGS);
    tracer.setRawSql("select * from metrics");
    AgentHelper.setLastTracer(tracer);
    tracer.provideConnection(connection);
    ConnectionFactory connectionFactory = createConnectionFactory(connection);
    tracer.setConnectionFactory(connectionFactory);
    tracer.finish(Opcodes.ARETURN, new DummyResultSet());
    String notExpectedRollupMetricName = getScopedInstanceDBMetric(DatastoreVendor.MySQL.name(), "localhost", "8080");
    Assert.assertFalse(tracer.getRolledUpMetricNamesForTesting().contains(notExpectedRollupMetricName));
    String expectedRollupMetricName = getScopedInstanceDBMetric(DatastoreVendor.MySQL.name(), DatastoreMetrics.HOSTNAME, "8080");
    Assert.assertTrue(String.format("Expected instance metric %s found", expectedRollupMetricName), tracer.getRolledUpMetricNamesForTesting().contains(expectedRollupMetricName));
    Transaction.clearTransaction();
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) InetSocketAddress(java.net.InetSocketAddress) Connection(java.sql.Connection) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) DummyResultSet(sql.DummyResultSet) Test(org.junit.Test)

Example 47 with ClassMethodSignature

use of com.newrelic.agent.tracers.ClassMethodSignature in project newrelic-java-agent by newrelic.

the class DatabaseServiceTest method instanceDisabled.

@Test
public void instanceDisabled() throws Exception {
    Map<String, Object> configMap = createStagingMap();
    Map<String, Object> dbConfigMap = createMap();
    Map<String, Object> nestedMap = new HashMap<>();
    nestedMap.put(DatastoreConfigImpl.ENABLED, !DatastoreConfigImpl.INSTANCE_REPORTING_DEFAULT_ENABLED);
    dbConfigMap.put(DatastoreConfigImpl.INSTANCE_REPORTING, nestedMap);
    configMap.put(AgentConfigImpl.DATASTORE_TRACER, dbConfigMap);
    createServiceManager(configMap);
    final Connection connection = Mockito.mock(Connection.class);
    Transaction transaction = Transaction.getTransaction(true);
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    TestDefaultSqlTracer tracer = new TestDefaultSqlTracer(transaction, sig, null, new SimpleMetricNameFormat(null), DefaultTracer.DEFAULT_TRACER_FLAGS);
    ConnectionFactory connectionFactory = createConnectionFactory(connection);
    tracer.setConnectionFactory(connectionFactory);
    tracer.setRawSql("select * from metrics");
    tracer.provideConnection(connection);
    AgentHelper.setLastTracer(tracer);
    tracer.finish(Opcodes.ARETURN, new DummyResultSet());
    String expectedRollupMetricName = getScopedInstanceDBMetric(DatastoreVendor.MySQL.name(), "unknown", "unknown");
    Assert.assertFalse(tracer.getRolledUpMetricNamesForTesting().contains(expectedRollupMetricName));
    Transaction.clearTransaction();
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) HashMap(java.util.HashMap) Connection(java.sql.Connection) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) DummyResultSet(sql.DummyResultSet) Test(org.junit.Test)

Example 48 with ClassMethodSignature

use of com.newrelic.agent.tracers.ClassMethodSignature in project newrelic-java-agent by newrelic.

the class AbstractPriorityTransactionNamingPolicyTest method startOtherTransaction.

private void startOtherTransaction() throws Exception {
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("", "", "");
    MetricNameFormat format = new SimpleMetricNameFormat("");
    Tracer tracer = new OtherRootTracer(tx, sig, this, format);
    tx.getTransactionActivity().tracerStarted(tracer);
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 49 with ClassMethodSignature

use of com.newrelic.agent.tracers.ClassMethodSignature in project newrelic-java-agent by newrelic.

the class AsyncTimeoutTransactionTest method createDispatcherTracer.

// Create a Tracer for tests that require one.
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);
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse)

Example 50 with ClassMethodSignature

use of com.newrelic.agent.tracers.ClassMethodSignature in project newrelic-java-agent by newrelic.

the class AsyncTransactionTest method createDispatcherTracer.

// Create a Tracer for tests that require one.
private BasicRequestRootTracer createDispatcherTracer(String methodName) {
    Transaction tx = Transaction.getTransaction();
    MockHttpRequest httpRequest = new MockHttpRequest();
    MockHttpResponse httpResponse = new MockHttpResponse();
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), methodName, "()V");
    BasicRequestRootTracer brrt = new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
    tx.setDispatcher(brrt.createDispatcher());
    return brrt;
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse)

Aggregations

ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)112 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)69 Transaction (com.newrelic.agent.Transaction)60 Test (org.junit.Test)55 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)46 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)44 Tracer (com.newrelic.agent.tracers.Tracer)41 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)26 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)23 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)20 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)17 HashMap (java.util.HashMap)17 TransactionData (com.newrelic.agent.TransactionData)16 JSONObject (org.json.simple.JSONObject)15 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)13 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)12 JSONArray (org.json.simple.JSONArray)11 MethodExitTracer (com.newrelic.agent.tracers.MethodExitTracer)10 Response (com.newrelic.api.agent.Response)10 TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)9