Search in sources :

Example 1 with JdbcDataSourceConnectionFactory

use of com.newrelic.agent.bridge.datastore.JdbcDataSourceConnectionFactory 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() 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));
        }
        return connection;
    } catch (Exception e) {
        AgentBridge.getAgent().getMetricAggregator().incrementCounter(DatastoreMetrics.DATABASE_ERRORS_ALL);
        throw e;
    } finally {
        if (firstInConnectPath) {
            DatastoreInstanceDetection.stopDetectingConnectionAddress();
        }
    }
}
Also used : DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor) JdbcDataSourceConnectionFactory(com.newrelic.agent.bridge.datastore.JdbcDataSourceConnectionFactory) Connection(java.sql.Connection) Trace(com.newrelic.api.agent.Trace)

Example 2 with JdbcDataSourceConnectionFactory

use of com.newrelic.agent.bridge.datastore.JdbcDataSourceConnectionFactory 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();
        }
    }
}
Also used : DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor) JdbcDataSourceConnectionFactory(com.newrelic.agent.bridge.datastore.JdbcDataSourceConnectionFactory) Connection(java.sql.Connection) Trace(com.newrelic.api.agent.Trace)

Example 3 with JdbcDataSourceConnectionFactory

use of com.newrelic.agent.bridge.datastore.JdbcDataSourceConnectionFactory 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;
    }
}
Also used : DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor) JdbcDataSourceConnectionFactory(com.newrelic.agent.bridge.datastore.JdbcDataSourceConnectionFactory) Connection(java.sql.Connection) DataSource(javax.sql.DataSource) Trace(com.newrelic.api.agent.Trace)

Example 4 with JdbcDataSourceConnectionFactory

use of com.newrelic.agent.bridge.datastore.JdbcDataSourceConnectionFactory 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;
    }
}
Also used : DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor) JdbcDataSourceConnectionFactory(com.newrelic.agent.bridge.datastore.JdbcDataSourceConnectionFactory) Connection(java.sql.Connection) DataSource(javax.sql.DataSource) Trace(com.newrelic.api.agent.Trace)

Aggregations

DatabaseVendor (com.newrelic.agent.bridge.datastore.DatabaseVendor)4 JdbcDataSourceConnectionFactory (com.newrelic.agent.bridge.datastore.JdbcDataSourceConnectionFactory)4 Trace (com.newrelic.api.agent.Trace)4 Connection (java.sql.Connection)4 DataSource (javax.sql.DataSource)2