Search in sources :

Example 1 with SqlTracer

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

the class TransactionTrace method processSqlTracer.

private void processSqlTracer(Tracer tracer) {
    if (tracer instanceof SqlTracer) {
        SqlTracer sqlTracer = (SqlTracer) tracer;
        ExplainPlanExecutor explainExecutor = sqlTracer.getExplainPlanExecutor();
        ConnectionFactory connectionFactory = sqlTracer.getConnectionFactory();
        if (!sqlTracer.hasExplainPlan() && explainExecutor != null && connectionFactory != null) {
            List<ExplainPlanExecutor> tracers = sqlTracers.get(connectionFactory);
            if (tracers == null) {
                tracers = new LinkedList<>();
                sqlTracers.put(connectionFactory, tracers);
            }
            tracers.add(explainExecutor);
        }
    }
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) ExplainPlanExecutor(com.newrelic.agent.database.ExplainPlanExecutor) SqlTracer(com.newrelic.agent.tracers.SqlTracer)

Example 2 with SqlTracer

use of com.newrelic.agent.tracers.SqlTracer 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 3 with SqlTracer

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

the class BoundedConcurrentCacheTest method testPutIfAbsent.

@Test
public void testPutIfAbsent() {
    RandomSql sql1 = createRandomSql();
    String obfuscatedSql1 = sqlObfuscator.obfuscateSql(sql1.getSql());
    RandomSql sql2 = createRandomSql();
    String obfuscatedSql2 = sqlObfuscator.obfuscateSql(sql2.getSql());
    SqlTracer tracer1 = createSqlTracer(2000, sql1);
    SqlTracer tracer2 = createSqlTracer(2000, sql2);
    SlowQueryInfo info1 = new SlowQueryInfo(createTransactionData(0L), tracer1, sql1.getSql(), obfuscatedSql1, agentConfig.getSqlTraceConfig());
    SlowQueryInfo info2 = new SlowQueryInfo(createTransactionData(0L), tracer1, sql1.getSql(), obfuscatedSql1, agentConfig.getSqlTraceConfig());
    SlowQueryInfo info3 = new SlowQueryInfo(createTransactionData(0L), tracer2, sql2.getSql(), obfuscatedSql2, agentConfig.getSqlTraceConfig());
    String sqlString1 = sql1.getSql();
    String sqlString2 = sql2.getSql();
    Assert.assertTrue(0 != sqlString1.compareTo(sqlString2));
    cache.putIfAbsent(sqlString1, info1);
    cache.putIfAbsent(sqlString1, info2);
    cache.putIfAbsent(sqlString2, info3);
    Assert.assertEquals(2, cache.size());
    Assert.assertTrue(cache.get(sqlString1) == info1);
    Assert.assertFalse(cache.get(sqlString1) == info2);
}
Also used : DefaultSqlTracer(com.newrelic.agent.tracers.DefaultSqlTracer) SqlTracer(com.newrelic.agent.tracers.SqlTracer) Test(org.junit.Test)

Example 4 with SqlTracer

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

the class BoundedConcurrentCacheTest method testPutReplace.

@Test
public void testPutReplace() {
    RandomSql sql = createRandomSql();
    String obfuscatedSql = sqlObfuscator.obfuscateSql(sql.getSql());
    SqlTracer tracer1 = createSqlTracer(2000, sql);
    SqlTracer tracer2 = createSqlTracer(3000, sql);
    SlowQueryInfo info1 = new SlowQueryInfo(createTransactionData(0L), tracer1, sql.getSql(), obfuscatedSql, agentConfig.getSqlTraceConfig());
    SlowQueryInfo info2 = new SlowQueryInfo(createTransactionData(0L), tracer2, sql.getSql(), obfuscatedSql, agentConfig.getSqlTraceConfig());
    String sqlString = sql.getSql();
    cache.putReplace(sqlString, info1);
    cache.putReplace(sqlString, info2);
    SlowQueryInfo value = cache.get(sqlString);
    Assert.assertEquals(tracer2, value.getTracer());
    value = null;
    cache.putReplace(sqlString, info1);
    value = cache.get(sqlString);
    Assert.assertEquals(tracer1, value.getTracer());
}
Also used : DefaultSqlTracer(com.newrelic.agent.tracers.DefaultSqlTracer) SqlTracer(com.newrelic.agent.tracers.SqlTracer) Test(org.junit.Test)

Example 5 with SqlTracer

use of com.newrelic.agent.tracers.SqlTracer 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

SqlTracer (com.newrelic.agent.tracers.SqlTracer)14 DefaultSqlTracer (com.newrelic.agent.tracers.DefaultSqlTracer)7 Test (org.junit.Test)6 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)4 Transaction (com.newrelic.agent.Transaction)3 ConnectionFactory (com.newrelic.agent.bridge.datastore.ConnectionFactory)3 Connection (java.sql.Connection)3 TransactionData (com.newrelic.agent.TransactionData)2 DatabaseVendor (com.newrelic.agent.bridge.datastore.DatabaseVendor)2 UnknownDatabaseVendor (com.newrelic.agent.bridge.datastore.UnknownDatabaseVendor)2 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)2 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)2 Tracer (com.newrelic.agent.tracers.Tracer)2 Statement (java.sql.Statement)2 ArrayList (java.util.ArrayList)2 DummyConnection (sql.DummyConnection)2 MockDispatcher (com.newrelic.agent.MockDispatcher)1 MockDispatcherTracer (com.newrelic.agent.MockDispatcherTracer)1 TransactionActivity (com.newrelic.agent.TransactionActivity)1 TransactionDataList (com.newrelic.agent.TransactionDataList)1