From 80cb1b0d23e222f28939f23d1ada044bcebfe985 Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Fri, 15 Mar 2024 20:58:59 +0100 Subject: [PATCH] Fix capture_stacktrace, and document that this is quite useless --- sentry_sdk_extensions/__init__.py | 46 ++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/sentry_sdk_extensions/__init__.py b/sentry_sdk_extensions/__init__.py index 35f7ee5..0d155d0 100644 --- a/sentry_sdk_extensions/__init__.py +++ b/sentry_sdk_extensions/__init__.py @@ -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}