Skip to content

Commit ef374d0

Browse files
committed
Make SENTRY_DSN an optional env var
Why these changes are being introduced: There has long been some friction with the SENTRY_DSN env var. In a production setting we ideally do not want an application to get deployed without the SENTRY_DSN set. At the same time, it's really not operationally required for most applications. It's probably the wrong ergonomics to have it checked generally and always at the config level, when it's more of a deployed check. How this addresses that need: * make SENTRY_DSN optional * issues a WARNING log message when unset or explicit "None" value Side effects of this change: * An application could get deployed without a SENTRY_DSN * We can, and should, look at deploy practices that will enforce SENTRY_DSN being present Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/IN-1542
1 parent 9c7d283 commit ef374d0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lambdas/config.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99

1010

1111
class Config:
12-
REQUIRED_ENV_VARS = (
13-
"WORKSPACE",
14-
"SENTRY_DSN",
15-
)
16-
OPTIONAL_ENV_VARS = ("WARNING_ONLY_LOGGERS",)
12+
REQUIRED_ENV_VARS = ("WORKSPACE",)
13+
OPTIONAL_ENV_VARS = ("WARNING_ONLY_LOGGERS", "SENTRY_DSN")
1714

1815
def check_required_env_vars(self) -> None:
1916
"""Method to raise exception if required env vars not set."""
@@ -103,4 +100,4 @@ def configure_sentry() -> None:
103100
"Sentry DSN found, exceptions will be sent to Sentry with env=%s", env
104101
)
105102
else:
106-
logger.info("No Sentry DSN found, exceptions will not be sent to Sentry")
103+
logger.warning("No Sentry DSN found, exceptions will not be sent to Sentry")

tests/test_config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ def test_config_doesnt_configure_sentry_if_dsn_not_present(caplog, monkeypatch):
2323
assert "No Sentry DSN found, exceptions will not be sent to Sentry" in caplog.text
2424

2525

26+
def test_config_doesnt_configure_sentry_if_dsn_is_explicit_none(caplog, monkeypatch):
27+
monkeypatch.setenv("SENTRY_DSN", "None")
28+
configure_sentry()
29+
assert "No Sentry DSN found, exceptions will not be sent to Sentry" in caplog.text
30+
31+
2632
def test_config_missing_required_env_vars(monkeypatch):
2733
monkeypatch.delenv("WORKSPACE")
2834
with pytest.raises(

0 commit comments

Comments
 (0)