Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions sentry_sdk/spotlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import urllib.error
import urllib3

from itertools import chain

from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand All @@ -18,6 +20,7 @@


DEFAULT_SPOTLIGHT_URL = "http://localhost:8969/stream"
DJANGO_SPOTLIGHT_MIDDLEWARE_PATH = "sentry_sdk.spotlight.SpotlightMiddleware"


class SpotlightClient:
Expand Down Expand Up @@ -112,9 +115,18 @@ def setup_spotlight(options):
else:
return None

if settings is not None and env_to_bool(
os.environ.get("SENTRY_SPOTLIGHT_ON_ERROR", "1")
if (
settings is not None
and settings.DEBUG
and env_to_bool(os.environ.get("SENTRY_SPOTLIGHT_ON_ERROR", "1"))
):
settings.MIDDLEWARE.append("sentry_sdk.spotlight.SpotlightMiddleware")
try:
middleware = settings.MIDDLEWARE
if DJANGO_SPOTLIGHT_MIDDLEWARE_PATH not in middleware:
settings.MIDDLEWARE = type(middleware)(
chain(middleware, (DJANGO_SPOTLIGHT_MIDDLEWARE_PATH,))
)
except Exception as err:
logger.error("Cannot inject Spotlight middleware", exc_info=err)

return SpotlightClient(url)
Loading