import importlib


def _on_import_factory(module, raise_errors=True):
    """Factory to create an import hook for the provided module name"""
    def on_import(hook):
        # Import and patch module
        path = 'ddtrace.contrib.%s' % module
        imported_module = importlib.import_module(path)
        imported_module.patch()

    return on_import