Skip to content

Commit

Permalink
feat(sentry): introduce setting to configure traces sample rate
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Oct 11, 2023
1 parent 39c8c1a commit 3390852
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 12 additions & 1 deletion eligibility_server/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"],
Expand Down
5 changes: 5 additions & 0 deletions eligibility_server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
# Sentry

SENTRY_DSN = None
SENTRY_TRACES_SAMPLE_RATE = 0.0


class Configuration:
Expand Down Expand Up @@ -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"])

0 comments on commit 3390852

Please sign in to comment.