Fix capture_stacktrace, and document that this is quite useless

This commit is contained in:
Klaas van Schelven
2024-03-15 20:58:59 +01:00
parent 52bb5a253b
commit 80cb1b0d23

View File

@@ -8,24 +8,38 @@ class AdHocException(Exception):
def capture_stacktrace(message):
"""
Capture the current stacktrace and send it to Sentry; the standard sentry_sdk does not provide this; it either
allows for sending arbitrary messages (but without local variables on your stacktrace) or it allows for sending
exceptions (but you have to raise an exception to capture the stacktrace).
Capture the current stacktrace and send it to Sentry _as a log entry with stacktrace context; the standard
sentry_sdk does not provide this; it either allows for sending arbitrary messages (but without local variables on
your stacktrace) or it allows for sending exceptions (but you have to raise an exception to capture the stacktrace).
Support for this (logging with stacktrace) server-side (as of March 15 2024):
* Bugsink: no stacktrace info displayed
* GlitchTip: no stacktrace info displayed
* Sentry: not checked
"""
client_options = sentry_sdk.client.get_options()
event = {}
with capture_internal_exceptions():
stacktrace = current_stacktrace(client_options["with_locals"])
stacktrace["frames"].pop() # Remove the last frame, which is the present function
event["threads"] = {
"values": [
{
"stacktrace": stacktrace,
"crashed": False,
"current": True,
}
]
}
# with capture_internal_exceptions(): commented out; I'd rather see the exception than swallow it
# client_options = sentry_sdk.client.get_options()
# client_options["include_local_variables"] for this and other parameters to current_stacktrace to
# current_stacktrace() I'm just going to accept the default values. The default values are fine _to me_ and I'm not
# in the business of developing a generic set of sentry_sdk_extensions, but rather to have a few extensions that are
# useful in the context of developing Bugsink, and having another Bugsink to send those to.
# (The reason not to parse client_options is: Sentry might change their names and I don't want the maintenance)
stacktrace = current_stacktrace()
stacktrace["frames"].pop() # Remove the last frame, which is the present function
event["threads"] = {
"values": [
{
"stacktrace": stacktrace,
"crashed": False,
"current": True,
}
]
}
event["level"] = "error"
event["logentry"] = {"message": message}