Exemplo n.º 1
0
def instrument_sqlite3_dbapi2(module):
    register_database_client(module,
                             'SQLite',
                             quoting_style='single+double',
                             instance_info=instance_info)

    wrap_object(module, 'connect', ConnectionFactory, (module, ))
Exemplo n.º 2
0
def instrument_cx_oracle(module):
    register_database_client(module,
                             database_product='Oracle',
                             quoting_style='single+oracle')

    wrap_object(module, 'connect', ConnectionFactory, (module, ))
    wrap_object(module, 'SessionPool', CreateSessionPoolProxy, (module, ))
Exemplo n.º 3
0
def instrument_psycopg2cffi(module):
    register_database_client(module, database_product='Postgres',
            quoting_style='single', explain_query='explain',
            explain_stmts=('select', 'insert', 'update', 'delete'),
            instance_info=instance_info)

    wrap_object(module, 'connect', ConnectionFactory, (module,))
def instrument_pymssql(module):
    # XXX Don't believe MSSQL provides a simple means of doing an
    # explain plan using one SQL statement prefix, eg., 'EXPLAIN'.

    register_database_client(module, database_product='MSSQL',
            quoting_style='single')

    wrap_object(module, 'connect', ConnectionFactory, (module,))
Exemplo n.º 5
0
def instrument_sqlite3(module):
    # This case is to handle where the sqlite3 module was already
    # imported prior to agent initialization. In this situation, a
    # reference to the connect() method would already have been created
    # which referred to the uninstrumented version of the function
    # originally imported by sqlite3.dbapi2 before instrumentation could
    # be applied.

    if not isinstance(module.connect, ConnectionFactory):
        register_database_client(module, 'SQLite', instance_info=instance_info)

        wrap_object(module, 'connect', ConnectionFactory, (module, ))
Exemplo n.º 6
0
def instrument_postgresql_interface_proboscis_dbapi2(module):
    register_database_client(module,
                             database_product='Postgres',
                             quoting_style='single+dollar',
                             explain_query='explain',
                             explain_stmts=('select', 'insert', 'update',
                                            'delete'),
                             instance_info=instance_info)

    from newrelic.hooks.database_dbapi2 import ConnectionFactory

    wrap_object(module, 'connect', ConnectionFactory, (module, ))
def test_datastore_instance(name, system_hostname, db_hostname, product, port,
                            unix_socket, database_path,
                            expected_instance_metric, monkeypatch):

    monkeypatch.setattr('newrelic.common.system_info.gethostname',
                        lambda: system_hostname)

    class FakeModule():
        pass

    register_database_client(FakeModule, product)
    enable_datastore_instance_feature(FakeModule)

    port_path_or_id = port or database_path or unix_socket

    node = DatabaseNode(
        dbapi2_module=FakeModule,
        sql='',
        children=[],
        start_time=0,
        end_time=1,
        duration=1,
        exclusive=1,
        stack_trace=None,
        sql_format='obfuscated',
        connect_params=None,
        cursor_params=None,
        sql_parameters=None,
        execute_params=None,
        host=db_hostname,
        port_path_or_id=port_path_or_id,
        database_name=database_path,
        guid=None,
        agent_attributes={},
        user_attributes={},
    )

    empty_stats = StatsEngine()
    transaction = current_transaction()
    unscoped_scope = ''

    # Check 'Datastore/instance' metric to confirm that:
    #   1. metric name is reported correctly
    #   2. metric scope is always unscoped

    for metric in node.time_metrics(empty_stats, transaction, None):
        if metric.name.startswith("Datastore/instance/"):
            assert metric.name == expected_instance_metric, name
            assert metric.scope == unscoped_scope
Exemplo n.º 8
0
def instrument_oursql(module):
    register_database_client(module, database_product='MySQL',
            quoting_style='single+double', explain_query='explain',
            explain_stmts=('select',), instance_info=instance_info)

    wrap_object(module, 'connect', ConnectionFactory, (module,))

    # The connect() function is actually aliased with Connect() and
    # Connection, the later actually being the Connection type object.
    # Instrument Connect(), but don't instrument Connection in case that
    # interferes with direct type usage. If people are using the
    # Connection object directly, they should really be using connect().

    if hasattr(module, 'Connect'):
        wrap_object(module, 'Connect', ConnectionFactory, (module,))
Exemplo n.º 9
0
        if isinstance(addr, str):
            host = "localhost"
            port = addr
        else:
            host, port = addr

        return (host, port, getattr(con_params, "database", None))

    @classmethod
    def instance_info(cls, args, kwargs):
        return cls._instance_info(*args, **kwargs)


register_database_client(
    PostgresApi,
    "Postgres",
    quoting_style="single+dollar",
    instance_info=PostgresApi.instance_info,
)
enable_datastore_instance_feature(PostgresApi)


class ProtocolProxy(ObjectProxy):
    async def bind_execute(self, state, *args, **kwargs):
        with DatabaseTrace(
                state.query,
                dbapi2_module=PostgresApi,
                connect_params=getattr(self, "_nr_connect_params", None),
        ):
            return await self.__wrapped__.bind_execute(state, *args, **kwargs)

    async def bind_execute_many(self, state, *args, **kwargs):
Exemplo n.º 10
0
def instrument(module):
    register_database_client(module, 'DBAPI2', 'single')

    wrap_object(module, 'connect', ConnectionFactory, (module,))
Exemplo n.º 11
0
def instrument_pyodbc(module):
    register_database_client(module,
                             database_product='ODBC',
                             quoting_style='single')

    wrap_object(module, 'connect', ConnectionFactory, (module, ))
Exemplo n.º 12
0
def instrument_ibm_db_dbi(module):
    register_database_client(module, database_product='IBMDB2',
            quoting_style='single', explain_query='EXPLAIN',
            explain_stmts=('select', 'insert', 'update', 'delete'))

    wrap_object(module, 'connect', ConnectionFactory, (module,))