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

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.

Hey @serg555, welcome to the community!

I think your best bet is to set ELASTIC_APM_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!

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

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