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
 def create_node(self):
     return DatabaseNode(dbapi2_module=self.dbapi2_module,
                         sql=self.sql,
                         children=self.children,
                         start_time=self.start_time,
                         end_time=self.end_time,
                         duration=self.duration,
                         exclusive=self.exclusive,
                         stack_trace=self.stack_trace,
                         sql_format=self.sql_format,
                         connect_params=self.connect_params,
                         cursor_params=self.cursor_params,
                         sql_parameters=self.sql_parameters,
                         execute_params=self.execute_params,
                         host=self.host,
                         port_path_or_id=self.port_path_or_id,
                         database_name=self.database_name,
                         is_async=self.is_async,
                         guid=self.guid)