Skip to content

Commit 1be7a85

Browse files
committed
Feature: show Sentry error ID to patrons
This is so patrons can report the specific Sentry error ID.
1 parent e5b03c5 commit 1be7a85

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

openlibrary/plugins/openlibrary/code.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,16 +1161,18 @@ def internalerror():
11611161
# TODO: move this to plugins\openlibrary\sentry.py
11621162
from openlibrary.plugins.openlibrary.sentry import sentry
11631163

1164+
event_id: str | None = None
11641165
if sentry.enabled:
1165-
sentry.capture_exception_webpy()
1166+
event_id = sentry.capture_exception_webpy()
11661167

11671168
if features.is_enabled('debug'):
11681169
raise web.debugerror()
11691170
else:
1171+
name = event_id if event_id else name
11701172
msg = render.site(
11711173
render.internalerror(name, etype=exception_type, evalue=exception_value)
11721174
)
1173-
raise web.internalerror(web.safestr(msg))
1175+
raise web.internalerror(msg)
11741176

11751177

11761178
delegate.app.internalerror = internalerror

openlibrary/utils/sentry.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ def capture_exception():
8383
app.internalerror = capture_exception
8484
app.add_processor(WebPySentryProcessor(app))
8585

86-
def capture_exception_webpy(self):
87-
with sentry_sdk.new_scope() as scope:
86+
def capture_exception_webpy(self) -> str | None:
87+
with sentry_sdk.push_scope() as scope:
8888
scope.add_event_processor(add_web_ctx_to_event)
8989
sentry_sdk.capture_exception()
90+
transaction = sentry_sdk.get_current_scope().transaction
91+
trace_id = transaction.trace_id if transaction else None
92+
return trace_id
93+
9094

9195
def capture_exception(self, ex, extras: dict | None = None):
9296
with sentry_sdk.new_scope() as scope:

0 commit comments

Comments
 (0)