I am working on setting up APM for a Django Rest API. We would like to use feature flags and query params to explore and toggle transaction capturing while at the same time excluding the bulk of our views from capture via the TRANSACTIONS_IGNORE_PATTERNS setting. Is this possible?

I set up a generic decorator that I am using to wrap DRF view methods and then calling using the capture_space context manager but it looks like the TransactionStore._should_ignore method is still returning True resulting in the capture being filtered out. Is there a way to override that behavior? I suppose I could see if could have the custom decorator rename the wrapped function on the fly in a way the causes the ignored_transaction_pattern matching to overlook the function, but that seems rather messy?

Hi Sasha

that's an interesting use case, but I'm afraid we don't have direct support for it. It seems like the idea you bring up with a decorator could work, but instead of renaming the view function, you could set the transaction name yourself, using elasticapm.set_transaction_name(). I don't think that would be too messy :slight_smile:

Ah, perfect! That worked exactly as expected. It does feel a bit awkward to call, but only because it seems to assume the presence of a local transaction and in the context of a class-based view you just have to know that the transaction starts at at the start of the request-cycle. That said, I think that I can abstract that awkwardness away in our local implementation. Thanks for the quick reply.

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