diff --git a/api/integrations/sentry/apps.py b/api/integrations/sentry/apps.py index ba110d01ffb1..92c57c09537e 100644 --- a/api/integrations/sentry/apps.py +++ b/api/integrations/sentry/apps.py @@ -3,7 +3,7 @@ from django.conf import settings from sentry_sdk.integrations.django import DjangoIntegration -from .samplers import block_health_sampler +from .samplers import block_non_functional_endpoints_sampler class SentryConfig(AppConfig): @@ -15,7 +15,7 @@ def ready(self): dsn=settings.SENTRY_SDK_DSN, integrations=[DjangoIntegration()], environment=settings.ENV, - traces_sampler=block_health_sampler, + traces_sampler=block_non_functional_endpoints_sampler, # If you wish to associate users to errors (assuming you are using # django.contrib.auth) you may enable sending PII data. send_default_pii=True, diff --git a/api/integrations/sentry/samplers.py b/api/integrations/sentry/samplers.py index 78065d73fdef..0171457ffda3 100644 --- a/api/integrations/sentry/samplers.py +++ b/api/integrations/sentry/samplers.py @@ -1,9 +1,11 @@ from django.conf import settings -def block_health_sampler(ctx): +def block_non_functional_endpoints_sampler(ctx): + non_functional_endpoints = ["/health", "/"] + sample_rate = settings.SENTRY_TRACE_SAMPLE_RATE wsgi_env = ctx.get("wsgi_environ") - if wsgi_env and wsgi_env.get("PATH_INFO") == "/health": + if wsgi_env and wsgi_env.get("PATH_INFO") in non_functional_endpoints: sample_rate = 0 return sample_rate diff --git a/api/integrations/sentry/tests/test_sampler.py b/api/integrations/sentry/tests/test_sampler.py index 60c7f926333e..6859351cc3ea 100644 --- a/api/integrations/sentry/tests/test_sampler.py +++ b/api/integrations/sentry/tests/test_sampler.py @@ -1,38 +1,50 @@ from django.test import override_settings -from integrations.sentry.samplers import block_health_sampler +from integrations.sentry.samplers import block_non_functional_endpoints_sampler SAMPLE_RATE = 10 @override_settings(SENTRY_TRACE_SAMPLE_RATE=SAMPLE_RATE) -def test_block_health_sampler_empty_context_returns_defaut_sample_rate(): +def test_block_non_functional_endpoints_sampler_empty_context_returns_defaut_sample_rate(): # When - sample_rate = block_health_sampler({}) + sample_rate = block_non_functional_endpoints_sampler({}) # Then assert sample_rate == SAMPLE_RATE @override_settings(SENTRY_TRACE_SAMPLE_RATE=SAMPLE_RATE) -def test_block_health_sampler_returns_0_for_health_check_transaction(): +def test_block_non_functional_endpoints_sampler_returns_0_for_health_check_transaction(): # Given ctx = {"wsgi_environ": {"PATH_INFO": "/health"}} # When - sample_rate = block_health_sampler(ctx) + sample_rate = block_non_functional_endpoints_sampler(ctx) # Then assert sample_rate == 0 @override_settings(SENTRY_TRACE_SAMPLE_RATE=SAMPLE_RATE) -def test_block_health_sampler_returns_default_for_non_heath_check_transaction(): +def test_block_non_functional_endpoints_sampler_returns_0_for_home_page_transaction(): + # Given + ctx = {"wsgi_environ": {"PATH_INFO": "/"}} + + # When + sample_rate = block_non_functional_endpoints_sampler(ctx) + + # Then + assert sample_rate == 0 + + +@override_settings(SENTRY_TRACE_SAMPLE_RATE=SAMPLE_RATE) +def test_block_non_functional_endpoints_sampler_returns_default_for_non_heath_check_transaction(): # Given ctx = {"wsgi_env": {"PATH_INFO": "/home"}} # When - sample_rate = block_health_sampler(ctx) + sample_rate = block_non_functional_endpoints_sampler(ctx) # Then assert sample_rate == SAMPLE_RATE