From 339085241ad8c9d408270c789ef7a98531ca9cca Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Wed, 11 Oct 2023 15:49:07 +0000 Subject: [PATCH] feat(sentry): introduce setting to configure traces sample rate see also cal-itp/benefits#1360 --- eligibility_server/sentry.py | 13 ++++++++++++- eligibility_server/settings.py | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/eligibility_server/sentry.py b/eligibility_server/sentry.py index 49b5eb07..c2355950 100644 --- a/eligibility_server/sentry.py +++ b/eligibility_server/sentry.py @@ -29,6 +29,17 @@ def get_denylist(): return denylist +def get_traces_sample_rate(config: Configuration): + rate = config.sentry_traces_sample_rate + if rate < 0.0 or rate > 1.0: + logger.warning("SENTRY_TRACES_SAMPLE_RATE was not in the range [0.0, 1.0], defaulting to 0.0") + rate = 0.0 + else: + logger.info(f"SENTRY_TRACES_SAMPLE_RATE set to: {rate}") + + return rate + + def configure(config: Configuration): SENTRY_DSN = config.sentry_dsn if SENTRY_DSN: @@ -40,7 +51,7 @@ def configure(config: Configuration): integrations=[ FlaskIntegration(), ], - traces_sample_rate=1.0, + traces_sample_rate=get_traces_sample_rate(config), environment=SENTRY_ENVIRONMENT, release=release, in_app_include=["eligibility_server"], diff --git a/eligibility_server/settings.py b/eligibility_server/settings.py index def1e915..306e19ff 100644 --- a/eligibility_server/settings.py +++ b/eligibility_server/settings.py @@ -46,6 +46,7 @@ # Sentry SENTRY_DSN = None +SENTRY_TRACES_SAMPLE_RATE = 0.0 class Configuration: @@ -145,3 +146,7 @@ def csv_quotechar(self): def sentry_dsn(self): sentry_dsn = current_app.config["SENTRY_DSN"] return str(sentry_dsn) if sentry_dsn else None + + @property + def sentry_traces_sample_rate(self): + return float(current_app.config["SENTRY_TRACES_SAMPLE_RATE"])