use of com.newrelic.agent.bridge.datastore.DatabaseVendor in project newrelic-java-agent by newrelic.
the class DatabaseService method runExplainPlan.
private void runExplainPlan(ExplainPlanExecutor explainExecutor, ConnectionFactory connectionFactory) {
Connection connection = null;
try {
connection = connectionFactory.getConnection();
DatabaseVendor vendor = connectionFactory.getDatabaseVendor();
explainExecutor.runExplainPlan(this, connection, vendor);
} catch (Throwable t) {
String msg = MessageFormat.format("An error occurred executing an explain plan: {0}", t);
if (Agent.LOG.isLoggable(Level.FINER)) {
Agent.LOG.log(Level.FINER, msg, t);
} else {
Agent.LOG.fine(msg);
}
} finally {
if (connection != null) {
try {
connection.close();
} catch (Exception e) {
Agent.LOG.log(Level.FINER, "Unable to close connection", e);
}
}
}
}
use of com.newrelic.agent.bridge.datastore.DatabaseVendor in project newrelic-java-agent by newrelic.
the class DataSource_Weaved method getConnection.
// This is a leaf tracer because it's common for these methods to delegate to each other and we don't want double
// counts
@Trace(leaf = true)
public Connection getConnection(String username, String password) throws Exception {
boolean firstInConnectPath = !DatastoreInstanceDetection.shouldDetectConnectionAddress();
try {
DatastoreInstanceDetection.detectConnectionAddress();
Connection connection = Weaver.callOriginal();
AgentBridge.getAgent().getTracedMethod().addRollupMetricName(DatastoreMetrics.DATABASE_GET_CONNECTION);
DatastoreInstanceDetection.associateAddress(connection);
if (!JdbcHelper.connectionFactoryExists(connection)) {
String url = JdbcHelper.getConnectionURL(connection);
if (url == null) {
return connection;
}
// Detect correct vendor type and then store new connection factory based on URL
DatabaseVendor vendor = JdbcHelper.getVendor(getClass(), url);
JdbcHelper.putConnectionFactory(url, new JdbcDataSourceConnectionFactory(vendor, (DataSource) this, username, password));
}
return connection;
} catch (Exception e) {
AgentBridge.getAgent().getMetricAggregator().incrementCounter(DatastoreMetrics.DATABASE_ERRORS_ALL);
throw e;
} finally {
if (firstInConnectPath) {
DatastoreInstanceDetection.stopDetectingConnectionAddress();
}
}
}
use of com.newrelic.agent.bridge.datastore.DatabaseVendor in project newrelic-java-agent by newrelic.
the class JtdsDataSource_Instrumentation method getConnection.
// This is a leaf tracer because it's common for these methods to delegate to each other and we don't want double counts
@Trace(leaf = true)
public Connection getConnection(String username, String password) throws Exception {
try {
Connection connection = Weaver.callOriginal();
NewRelic.getAgent().getTracedMethod().addRollupMetricName(DatastoreMetrics.DATABASE_GET_CONNECTION);
if (!JdbcHelper.connectionFactoryExists(connection)) {
String url = JdbcHelper.getConnectionURL(connection);
if (url == null) {
return connection;
}
// Detect correct vendor type and then store new connection factory based on URL
DatabaseVendor vendor = JdbcHelper.getVendor(getClass(), url);
JdbcHelper.putConnectionFactory(url, new JdbcDataSourceConnectionFactory(vendor, (DataSource) this, username, password));
}
return connection;
} catch (Exception e) {
AgentBridge.getAgent().getMetricAggregator().incrementCounter(DatastoreMetrics.DATABASE_ERRORS_ALL);
throw e;
}
}
use of com.newrelic.agent.bridge.datastore.DatabaseVendor in project newrelic-java-agent by newrelic.
the class JtdsDataSource_Instrumentation method getConnection.
// This is a leaf tracer because it's common for these methods to delegate to each other and we don't want double counts
@Trace(leaf = true)
public Connection getConnection() throws Exception {
try {
Connection connection = Weaver.callOriginal();
AgentBridge.getAgent().getTracedMethod().addRollupMetricName(DatastoreMetrics.DATABASE_GET_CONNECTION);
if (!JdbcHelper.connectionFactoryExists(connection)) {
String url = JdbcHelper.getConnectionURL(connection);
if (url == null) {
return connection;
}
// Detect correct vendor type and then store new connection factory based on URL
DatabaseVendor vendor = JdbcHelper.getVendor(getClass(), url);
JdbcHelper.putConnectionFactory(url, new JdbcDataSourceConnectionFactory(vendor, (DataSource) this));
}
return connection;
} catch (Exception e) {
AgentBridge.getAgent().getMetricAggregator().incrementCounter(DatastoreMetrics.DATABASE_ERRORS_ALL);
throw e;
}
}
use of com.newrelic.agent.bridge.datastore.DatabaseVendor in project newrelic-java-agent by newrelic.
the class RequestUriConfigTests 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() {
return null;
}
@Override
public DatabaseVendor getDatabaseVendor() {
return UnknownDatabaseVendor.INSTANCE;
}
});
sqlTracer.setRawSql(sql);
tx.getTransactionActivity().tracerStarted(sqlTracer);
return sqlTracer;
}
Aggregations