Skip to content

fix: Open relevant error when SpotlightMiddleware is on #3614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 9 additions & 10 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,18 +753,16 @@ def capture_event(

:returns: An event ID. May be `None` if there is no DSN set or of if the SDK decided to discard the event for other reasons. In such situations setting `debug=True` on `init()` may help.
"""
if hint is None:
hint = {}
event_id = event.get("event_id")
hint = dict(hint or ()) # type: Hint

if event_id is None:
event["event_id"] = event_id = uuid.uuid4().hex
if not self._should_capture(event, hint, scope):
return None

profile = event.pop("profile", None)

event_id = event.get("event_id")
if event_id is None:
event["event_id"] = event_id = uuid.uuid4().hex
event_opt = self._prepare_event(event, hint, scope)
if event_opt is None:
return None
Expand Down Expand Up @@ -812,15 +810,16 @@ def capture_event(
for attachment in attachments or ():
envelope.add_item(attachment.to_envelope_item())

return_value = None
if self.spotlight:
self.spotlight.capture_envelope(envelope)
return_value = event_id

if self.transport is None:
return None

self.transport.capture_envelope(envelope)
if self.transport is not None:
self.transport.capture_envelope(envelope)
return_value = event_id

return event_id
return return_value

def capture_session(
self, session # type: Session
Expand Down
18 changes: 13 additions & 5 deletions sentry_sdk/spotlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,22 @@ def process_exception(self, _request, exception):
spotlight_url = spotlight_client.url.rsplit("/", 1)[0]

try:
spotlight = (
urllib.request.urlopen(spotlight_url).read().decode("utf-8")
).replace("<html>", f'<html><base href="{spotlight_url}">')
spotlight = urllib.request.urlopen(spotlight_url).read().decode("utf-8")
except urllib.error.URLError:
return None
else:
sentry_sdk.api.capture_exception(exception)
return HttpResponseServerError(spotlight)
event_id = sentry_sdk.api.capture_exception(exception)
return HttpResponseServerError(
spotlight.replace(
"<html>",
(
f'<html><base href="{spotlight_url}">'
'<script>window.__spotlight = {{ initOptions: {{ startFrom: "/errors/{event_id}" }}}};</script>'.format(
event_id=event_id
)
),
)
)

except ImportError:
settings = None
Expand Down
Loading