I have a Django application with a health check endpoint that's using django-health-check.
In the url_patterns
I have added the following line:
url(r'^ht/', include('health_check.urls')),
The issue is that the health check is filling all the Sentry transaction limits.
How can I exclude the health check endpoint in Sentry?
The way to handle this kind of cases is to use a sampling function to control the sample rate according to the URL or other parameters.
def traces_sampler(ctx):
if 'wsgi_environ' in ctx:
url = ctx['wsgi_environ'].get('PATH_INFO', '')
if url.startswith('/ht/'):
return 0 # Don't trace any
return 1 # Trace all
sentry_sdk.init(
# ...
traces_sampler=traces_sampler,
)
Here is a more complete example.
def traces_sampler(ctx):
if ctx['parent_sampled'] is not None:
# If this transaction has a parent, we usually want to sample it
# if and only if its parent was sampled.
return ctx['parent_sampled']
op = ctx['transaction_context']['op']
if 'wsgi_environ' in ctx:
# Get the URL for WSGI requests
url = ctx['wsgi_environ'].get('PATH_INFO', '')
elif 'asgi_scope' in ctx:
# Get the URL for ASGI requests
url = ctx['asgi_scope'].get('path', '')
else:
# Other kinds of transactions don't have a URL
url = ''
if op == 'http.server':
# Conditions only relevant to operation "http.server"
if url.startswith('/ht/'):
return 0 # Don't trace any of these transactions
return 0.1 # Trace 10% of other transactions
sentry_sdk.init(
# ...
traces_sampler=traces_sampler,
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With