When not dogfooding, just print a regular stacktrace in the logs

This will hopefully help when getting issue-reports for those that
have not set up dogfooding.

See [Dogfooding Bugsink](https://www.bugsink.com/docs/dogfooding/)
This commit is contained in:
Klaas van Schelven
2025-04-11 13:22:37 +02:00
parent 0c11bf0787
commit 1084796763
3 changed files with 30 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
import traceback
import types
from sentry_sdk.utils import current_stacktrace
@@ -111,3 +112,19 @@ def capture_stacktrace(message):
}
}
sentry_sdk.capture_event(event)
def capture_or_log_exception(e, logger):
try:
if sentry_sdk.is_initialized():
sentry_sdk.capture_exception(e)
else:
# this gnarly approach makes it so that each line of the traceback gets the same prefixes (dates etc)
for bunch_of_lines in traceback.format_exception(e):
for line in bunch_of_lines.splitlines():
# Note: when .is_initialized() is True, .error is spammy (it gets captured) but we don't have that
# problem in this branch.
logger.error(line)
except Exception as e2:
# We just never want our error-handling code to be the cause of an error.
print("Error in capture_or_log_exception", str(e2), "during handling of", str(e))