#How to disable automatic instrumentation within a context?

7 messages · Page 1 of 1 (latest)

merry marsh
#

I'm using Sentry Python, and have an ETL script that makes a lot of DB calls. I'm in a Sentry trace context, and there's a portion of code where it repeats a bunch of SQLAlchemy SQL queries with pagination, and since there are a lot of pages, I get way too many spans.
Generally I live the automatic instrumentation, but is it possible to disable automatic instrumentation for a portion of a code?

Here is what ChatGPT hallucinated for me as what I can do which does not seem to exist in Sentry, but would be accurate to what I'm looking for. Is there anything like this in Sentry Python?

arctic ridge
#

Unfortunately, we do not have a suppress_instrumentation api 🙂 (Maybe JS SDK has something liek this, but Python does not have)

#

This is a hook that is called when a transaction is finished (a transaction is the basically a root_span that has all spans that where added in one call to your etl script in it)

#

In there you get the transaction object and you can delete spans from that transaction.

#

Its not the most comfortable way to do what you want, but it works

merry marsh
#

that is a shame.
another alternative is to avoid Sentry span/transaction context except for the bits where I'm sure that I want to log all spans within it