Skip to content

Commit 17b87be

Browse files
committed
fix logging
1 parent 6a6881e commit 17b87be

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

sentry_sdk/spotlight.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import urllib.request
66
import urllib.error
77
import urllib3
8+
import sys
89

910
from itertools import chain, product
1011

@@ -24,6 +25,9 @@
2425
from sentry_sdk.envelope import Envelope
2526

2627

28+
logger = logging.getLogger("spotlight")
29+
30+
2731
DEFAULT_SPOTLIGHT_URL = "http://localhost:8969/stream"
2832
DJANGO_SPOTLIGHT_MIDDLEWARE_PATH = "sentry_sdk.spotlight.SpotlightMiddleware"
2933

@@ -112,21 +116,14 @@ def __init__(self, get_response):
112116
spotlight_js_url,
113117
method="HEAD",
114118
)
115-
status_code = urllib.request.urlopen(req).status
116-
if status_code >= 200 and status_code < 400:
117-
self._spotlight_script = SPOTLIGHT_JS_SNIPPET_PATTERN.format(
118-
spotlight_js_url
119-
)
120-
else:
121-
sentry_logger.debug(
122-
"Could not get Spotlight JS from %s (status: %s), SpotlightMiddleware will not be useful.",
123-
spotlight_js_url,
124-
status_code,
125-
)
126-
self._spotlight_script = None
119+
urllib.request.urlopen(req)
120+
self._spotlight_script = SPOTLIGHT_JS_SNIPPET_PATTERN.format(
121+
spotlight_js_url
122+
)
127123
except urllib.error.URLError as err:
128124
sentry_logger.debug(
129-
"Cannot get Spotlight JS to inject. SpotlightMiddleware will not be very useful.",
125+
"Cannot get Spotlight JS to inject at %s. SpotlightMiddleware will not be very useful.",
126+
spotlight_js_url,
130127
exc_info=err,
131128
)
132129
self._spotlight_script = None
@@ -204,6 +201,10 @@ def process_exception(self, _request, exception):
204201

205202
def setup_spotlight(options):
206203
# type: (Dict[str, Any]) -> Optional[SpotlightClient]
204+
_handler = logging.StreamHandler(sys.stderr)
205+
_handler.setFormatter(logging.Formatter(" [spotlight] %(levelname)s: %(message)s"))
206+
logger.addHandler(_handler)
207+
logger.setLevel(logging.INFO)
207208

208209
url = options.get("spotlight")
209210

@@ -225,9 +226,9 @@ def setup_spotlight(options):
225226
settings.MIDDLEWARE = type(middleware)(
226227
chain(middleware, (DJANGO_SPOTLIGHT_MIDDLEWARE_PATH,))
227228
)
228-
logging.info("Enabled Spotlight integration for Django")
229+
logger.info("Enabled Spotlight integration for Django")
229230

230231
client = SpotlightClient(url)
231-
logging.info("Enabled Spotlight at %s", url)
232+
logger.info("Enabled Spotlight using sidecar at %s", url)
232233

233234
return client

0 commit comments

Comments
 (0)