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

**URL:** <https://discuss.elastic.co/t/unable-to-use-mysqldb-cursor-execute-function-after-instantiating-elasticapm-in-flask/301403>\
**Category:** APM\
**Tags:** python\
**Created:** [April 3, 2022, 12:25am UTC](https://discuss.elastic.co/t/unable-to-use-mysqldb-cursor-execute-function-after-instantiating-elasticapm-in-flask/301403 "2022-04-03T00:25:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibbyzj](https://avatars.discourse-cdn.com/v4/letter/i/7feea3/32.png) [@ibbyzj](https://discuss.elastic.co/u/ibbyzj)\
**Post date:** [April 3, 2022, 12:25am UTC](https://discuss.elastic.co/t/unable-to-use-mysqldb-cursor-execute-function-after-instantiating-elasticapm-in-flask/301403/1 "2022-04-03T00:25:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ibbyzj](https://avatars.discourse-cdn.com/v4/letter/i/7feea3/32.png) [@ibbyzj](https://discuss.elastic.co/u/ibbyzj)\
**Post date:** [April 3, 2022, 12:48am UTC](https://discuss.elastic.co/t/unable-to-use-mysqldb-cursor-execute-function-after-instantiating-elasticapm-in-flask/301403/2 "2022-04-03T00:48:05Z")

</div>

I was able to read through library code and figure out it uses SKIP\_INSTRUMENT\_

see code from library below

```auto
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

```auto
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.

---

<div class="post-metadata">

**Author:** ![basepi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/basepi/32/53056_2.png) [@basepi](https://discuss.elastic.co/u/basepi)\
**Post date:** [April 4, 2022, 5:48pm UTC](https://discuss.elastic.co/t/unable-to-use-mysqldb-cursor-execute-function-after-instantiating-elasticapm-in-flask/301403/3 "2022-04-04T17:48:34Z")

</div>

I think this might be a bug in our MySQLdb instrumentation. Would you mind [opening an issue?](https://github.com/elastic/apm-agent-python/issues/new/choose)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 25, 2022, 1:48pm UTC](https://discuss.elastic.co/t/unable-to-use-mysqldb-cursor-execute-function-after-instantiating-elasticapm-in-flask/301403/4 "2022-04-25T13:48:54Z")

</div>

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