Hello, I've done quite a bit of searching and can't seem to find what I'm looking for. I enabled performance monitoring by setting traces_sample_rate > 0. However, I'd like to be able to filter some things from being recorded as transactions (health checks endpoints, ...). Is it possible to do this?
Within a view you can do:
def hello_world():
with configure_scope() as scope:
if scope.transaction:
scope.transaction.sampled = False
That will prevent the view from being sent.
@untitaker thanks for the response. This will resolve my immediate needs. A few ideas/suggestions:
transaction_exclude_list = ["/healhz", ...]@exclude_sentry_transaction or somethingThanks!
@kpurdon you're right, we don't yet want to commit to recommending this solution and haven't had time to design UX for this yet :(
I see the traceSampler option in python docs whIch could be used to filter the performance events, but it looks like it is not implemented yet.
@serebrov thanks, this was a mistake. I opened https://github.com/getsentry/sentry-docs/pull/2543
fyi we're working on something that will allow you to filter out transactions in before-send style (i.e. using a callback). Check #863 and related PRs.
I see you have introduced traces_sampler configuration in the release 0.19.2. Thank you!
However, it does not help me with Django base project.
All sampling_context for traces contains no information regarding url, view, or something else which can be used in filter:
{'transaction_context': {'trace_id': 'b99a0a8618454707868e12d73cd2d474', 'span_id': '9d161e8244e7fbf1', 'parent_span_id': None, 'same_process_as_parent': False, 'op': 'http.server', 'description': None, 'start_timestamp': datetime.datetime(2020, 11, 3, 17, 38, 12, 75112), 'timestamp': None, 'name': 'generic WSGI request', 'sampled': None, 'parent_sampled': None}, 'parent_sampled': None}
It there any possibility to make 'name': 'generic WSGI request' more specific?
After https://github.com/getsentry/sentry-python/pull/906 you will see some request data in the context. Please note that the sampling decision happens way before Django's routing so name will still be the "generic" value. But you will be able to access the URL.
The reason for starting transactions and the sampling decision so early is because middleware can already run database queries and have impact on response time that you'd likely want to see. The sampling decision has to be made too because at any time we might have to attach it as part of the trace header. You can later still override the decision with one of the techniques shown above (to opt-out a transaction from being sent), but that will produce data inconsistencies where other transactions from other services may inadvertently be sampled in.
Ideally you would make your sampling decision purely based on the context when it is finally ready and never change it again. However the above methods like setting sampled=False on the scope will continue to work as a billing bandaid. Just don't expect particularly consistent sampling.
When the time comes this will all be documented.
Most helpful comment
Within a view you can do:
That will prevent the view from being sent.