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);
}
}
}
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;
}
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);
}
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());
}
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;
}
Aggregations