Search in sources :

Example 6 with SimpleMetricNameFormat

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

the class DatastoreInstanceCrossAgentTests method createTracerInTransaction.

private DefaultTracer createTracerInTransaction() {
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "method", "()V");
    DefaultTracer tracer = new OtherRootTracer(tx, sig, this, new SimpleMetricNameFormat("test"));
    tx.getTransactionActivity().tracerStarted(tracer);
    tx.setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, true, "custom", "foo");
    Assert.assertEquals(0, AgentHelper.getChildren(tracer).size());
    return tracer;
}
Also used : Transaction(com.newrelic.agent.Transaction) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 7 with SimpleMetricNameFormat

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

the class DefaultSqlTracerTest method newInstanceDBTracer.

private DefaultSqlTracer newInstanceDBTracer(String sql, final Connection connection, final String dbVendor, final String dbVendorName) throws SQLException {
    Transaction transaction = Transaction.getTransaction(true);
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    DefaultSqlTracer result = new OtherRootSqlTracer(transaction, sig, null, new SimpleMetricNameFormat(null), DefaultTracer.DEFAULT_TRACER_FLAGS, System.nanoTime());
    transaction.getTransactionActivity().tracerStarted(result);
    final JdbcDatabaseVendor jdbcDatabaseVendor = new JdbcDatabaseVendor(dbVendor, dbVendorName, true) {

        @Override
        public DatastoreVendor getDatastoreVendor() {
            return DatastoreVendor.MySQL;
        }
    };
    ConnectionFactory connectionFactory = new ConnectionFactory() {

        @Override
        public Connection getConnection() throws SQLException {
            return connection;
        }

        @Override
        public DatabaseVendor getDatabaseVendor() {
            return jdbcDatabaseVendor;
        }
    };
    result.setConnectionFactory(connectionFactory);
    result.setRawSql(sql);
    result.provideConnection(connection);
    result.setConnectionFactory(connectionFactory);
    // prevent "Inconsistent state! ..." errors
    AgentHelper.setLastTracer(result);
    return result;
}
Also used : SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 8 with SimpleMetricNameFormat

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

the class DefaultTracerTest method exclusiveTime.

@Test
public void exclusiveTime() throws Exception {
    Transaction tx = Transaction.getTransaction();
    long parentDuration = 100;
    long childDuration = 100;
    int childCount = 3;
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
    DefaultTracer parentTracer = new OtherRootTracer(tx, sig, this, new SimpleMetricNameFormat("test"));
    tx.getTransactionActivity().tracerStarted(parentTracer);
    assertEquals(0, AgentHelper.getChildren(parentTracer).size());
    long actualChildDuratioNanos = 0;
    synchronized (this) {
        wait(parentDuration);
        for (int i = 0; i < childCount; i++) {
            DefaultTracer kid = new DefaultTracer(tx, sig, this);
            tx.getTransactionActivity().tracerStarted(kid);
            wait(childDuration);
            kid.finish(Opcodes.RETURN, null);
            // parentTracer.childTracerFinished(kid);
            actualChildDuratioNanos += kid.getDuration();
        }
    }
    parentTracer.finish(Opcodes.RETURN, null);
    Assert.assertTrue(parentTracer.getDurationInMilliseconds() >= parentDuration);
    Assert.assertNotSame(parentTracer.getExclusiveDuration(), parentTracer.getDuration());
    assertEquals(actualChildDuratioNanos, parentTracer.getDuration() - parentTracer.getExclusiveDuration());
    assertEquals(childCount, AgentHelper.getChildren(parentTracer).size());
}
Also used : Transaction(com.newrelic.agent.Transaction) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) Test(org.junit.Test)

Example 9 with SimpleMetricNameFormat

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

the class SqlTraceServiceTest method startSqlTracer.

private SqlTracer startSqlTracer(final String sql, final long duration) throws SQLException {
    DummyConnection conn = new DummyConnection();
    Statement statement = conn.createStatement();
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    SqlTracer sqlTracer = new OtherRootSqlTracer(tx, sig, statement, new SimpleMetricNameFormat(null)) {

        @Override
        public long getDuration() {
            return duration;
        }

        @Override
        public Object getSql() {
            return sql;
        }
    };
    sqlTracer.setConnectionFactory(new ConnectionFactory() {

        @Override
        public Connection getConnection() throws SQLException {
            return null;
        }

        @Override
        public DatabaseVendor getDatabaseVendor() {
            return UnknownDatabaseVendor.INSTANCE;
        }
    });
    sqlTracer.setRawSql(sql);
    tx.getTransactionActivity().tracerStarted(sqlTracer);
    return sqlTracer;
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor) UnknownDatabaseVendor(com.newrelic.agent.bridge.datastore.UnknownDatabaseVendor) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SQLException(java.sql.SQLException) Statement(java.sql.Statement) DummyConnection(sql.DummyConnection) Connection(java.sql.Connection) DummyConnection(sql.DummyConnection) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 10 with SimpleMetricNameFormat

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

the class BoundedConcurrentCacheTest method createSqlTracer.

public SqlTracer createSqlTracer(RandomSql sql) {
    SqlTracer defaultSqlTracer = new DefaultSqlTracer(tx, cms, new Object(), new SimpleMetricNameFormat("BoundedConcurrentCacheTest"), TracerFlags.GENERATE_SCOPED_METRIC);
    defaultSqlTracer.setRawSql(sql.getSql());
    return defaultSqlTracer;
}
Also used : DefaultSqlTracer(com.newrelic.agent.tracers.DefaultSqlTracer) SqlTracer(com.newrelic.agent.tracers.SqlTracer) DefaultSqlTracer(com.newrelic.agent.tracers.DefaultSqlTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

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