def install ( ) : @ monkeypatch_method ( BaseDatabaseWrapper ) def cursor ( original , self , * args , * * kwargs ) : result = original ( * args , * * kwargs ) return _DetailedTracingCursorWrapper ( result , self ) logger . debug ( "Monkey patched SQL" )
python monkeypatch instance method with another method
Installs ScoutApm SQL Instrumentation by monkeypatching the cursor method of BaseDatabaseWrapper to return a wrapper that instruments any calls going through it .
def install():
        """
        Installs ScoutApm SQL Instrumentation by monkeypatching the `cursor`
        method of BaseDatabaseWrapper, to return a wrapper that instruments any
        calls going through it.
        """

        @monkeypatch_method(BaseDatabaseWrapper)
        def cursor(original, self, *args, **kwargs):
            result = original(*args, **kwargs)
            return _DetailedTracingCursorWrapper(result, self)

        logger.debug("Monkey patched SQL")