# How to temporary disable SQL log capturing for heavy tasks in Python APM?

**URL:** <https://discuss.elastic.co/t/how-to-temporary-disable-sql-log-capturing-for-heavy-tasks-in-python-apm/244952>\
**Category:** APM\
**Tags:** python\
**Created:** [August 13, 2020, 10:13pm UTC](https://discuss.elastic.co/t/how-to-temporary-disable-sql-log-capturing-for-heavy-tasks-in-python-apm/244952 "2020-08-13T22:13:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![serg555](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/serg555/32/45707_2.png) [@serg555](https://discuss.elastic.co/u/serg555)\
**Post date:** [August 13, 2020, 10:13pm UTC](https://discuss.elastic.co/t/how-to-temporary-disable-sql-log-capturing-for-heavy-tasks-in-python-apm/244952/1 "2020-08-13T22:13:20Z")

</div>

I am using python APM library and trying to record a transaction for a heavy Django command that takes hours and runs thousands of queries in process:

```
elasticapm.instrument()
apm_client = get_client()
apm_client.begin_transaction(transaction_type='background_task')

heavy_task()

apm_client.end_transaction(name= __name__ , result='success')

```

This works but it generates too many sql query events in process (for each single query) which I don't want to collect, I just want to track transaction duration and any exceptions (couple events per run). Is there a way to achieve this?

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:** [August 14, 2020, 2:10pm UTC](https://discuss.elastic.co/t/how-to-temporary-disable-sql-log-capturing-for-heavy-tasks-in-python-apm/244952/2 "2020-08-14T14:10:57Z")

</div>

Hey @serg555, welcome to the community!

I think your best bet is to set [`ELASTIC_APM_TRANSACTION_MAX_SPANS`](https://www.elastic.co/guide/en/apm/agent/python/current/configuration.html#config-transaction-max-spans), which will limit the number of spans collected for a single transaction. Unfortunately, this setting is global, so it might be difficult to set it just for that heavy task. If that heavy task is a separate command/process (like a django management command) then you could probably set it via environment variable for that single command.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [August 19, 2020, 7:01am UTC](https://discuss.elastic.co/t/how-to-temporary-disable-sql-log-capturing-for-heavy-tasks-in-python-apm/244952/3 "2020-08-19T07:01:35Z")

</div>

Would this proposed `span_min_duration` option be appropriate for your use case? It's basically a setting to cut off fast spans: [https://github.com/elastic/apm/pull/314/files](https://github.com/elastic/apm/pull/314/files)

---

<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:** [September 9, 2020, 3:01am UTC](https://discuss.elastic.co/t/how-to-temporary-disable-sql-log-capturing-for-heavy-tasks-in-python-apm/244952/4 "2020-09-09T03:01:50Z")

</div>

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