Unable to use MySQLdb cursor execute function after instantiating ElasticAPM in Flask

Hello Team,

I am using APM flask client in my Flask APP. After I instantiate the apm object, I am unable to use existing MySQLdb function in my app, below is how I instantiate the class.

apm = ElasticAPM(app)

The error is get in my MySQLdb implementation when calling cursor execute function below cursor.execute(query=query)

TypeError: execute() got an unexpected keyword argument 'query'

I have identified the change in the apm library that is causing this.

The file is register.py,

and the commenting out the below line fixes the issue for me.

# "elasticapm.instrumentation.packages.mysql.MySQLInstrumentation",

Do you know why you are using this in the library?

I was able to read through library code and figure out it uses SKIP_INSTRUMENT_

see code from library below

skip_env_var = "SKIP_INSTRUMENT_" + str(self.name.upper())
        if skip_env_var in os.environ:
            logger.debug("Skipping instrumentation of %s. %s is set.", self.name, skip_env_var)
            return

As a fix in my code, I set the below

os.environ["SKIP_INSTRUMENT_MYSQL"] = "1"

This seems to have fixed the issue for me, but I'm still curious to know from the dev team why all registers/methods are instrumented with a wrapper.

Thanks.

I think this might be a bug in our MySQLdb instrumentation. Would you mind opening an issue?

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.