Skip to content

Commit

Permalink
fix(spotlight): Make Django middleware init even more defensive
Browse files Browse the repository at this point in the history
I just got faced with a situation where even trying to do `settings.DEBUG` may trigger a Django exception if the settings are not loaded yet, hence widening the `capture_internal_exceptions()` scope for this.
  • Loading branch information
BYK committed Dec 12, 2024
1 parent 6448c70 commit bce9e47
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions sentry_sdk/spotlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ def setup_spotlight(options):
if not isinstance(url, str):
return None

if (
settings is not None
and settings.DEBUG
and env_to_bool(os.environ.get("SENTRY_SPOTLIGHT_ON_ERROR", "1"))
and env_to_bool(os.environ.get("SENTRY_SPOTLIGHT_MIDDLEWARE", "1"))
):
with capture_internal_exceptions():
with capture_internal_exceptions():
if (
settings is not None
and settings.DEBUG
and env_to_bool(os.environ.get("SENTRY_SPOTLIGHT_ON_ERROR", "1"))
and env_to_bool(os.environ.get("SENTRY_SPOTLIGHT_MIDDLEWARE", "1"))
):
middleware = settings.MIDDLEWARE
if DJANGO_SPOTLIGHT_MIDDLEWARE_PATH not in middleware:
settings.MIDDLEWARE = type(middleware)(
Expand Down

0 comments on commit bce9e47

Please sign in to comment.