From d25fba854956f61d67164f4056f26e58420851a4 Mon Sep 17 00:00:00 2001 From: Koby Bass Date: Tue, 5 Mar 2019 11:37:49 +0200 Subject: [PATCH] Stacktrace: Pass with_locals parameter. (#279) * Stacktrace: Pass with_locals parameter. * fix: Formatting --- sentry_sdk/client.py | 2 +- sentry_sdk/integrations/logging.py | 5 +++-- tests/test_client.py | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index 611d4d55e7..3fa4492e10 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -118,7 +118,7 @@ def _prepare_event( with capture_internal_exceptions(): event["threads"] = [ { - "stacktrace": current_stacktrace(), + "stacktrace": current_stacktrace(self.options["with_locals"]), "crashed": False, "current": True, } diff --git a/sentry_sdk/integrations/logging.py b/sentry_sdk/integrations/logging.py index aac4be7178..a8b02b588e 100644 --- a/sentry_sdk/integrations/logging.py +++ b/sentry_sdk/integrations/logging.py @@ -158,12 +158,13 @@ def _emit(self, record): return hint = None # type: Optional[Dict[str, Any]] + client_options = hub.client.options # exc_info might be None or (None, None, None) if record.exc_info is not None and record.exc_info[0] is not None: event, hint = event_from_exception( record.exc_info, - client_options=hub.client.options, + client_options=client_options, mechanism={"type": "logging", "handled": True}, ) elif record.exc_info and record.exc_info[0] is None: @@ -172,7 +173,7 @@ def _emit(self, record): with capture_internal_exceptions(): event["threads"] = [ { - "stacktrace": current_stacktrace(), + "stacktrace": current_stacktrace(client_options["with_locals"]), "crashed": False, "current": True, } diff --git a/tests/test_client.py b/tests/test_client.py index 17b8dc8df2..907c187230 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -143,6 +143,26 @@ def bar(): assert functions[-2:] == ["foo", "bar"] +def test_attach_stacktrace_enabled_no_locals(): + events = [] + hub = Hub( + Client(attach_stacktrace=True, with_locals=False, transport=events.append) + ) + + def foo(): + bar() + + def bar(): + hub.capture_message("HI") + + foo() + + event, = events + thread, = event["threads"] + local_vars = [x.get("vars") for x in thread["stacktrace"]["frames"]] + assert local_vars[-2:] == [None, None] + + def test_attach_stacktrace_disabled(): events = [] hub = Hub(Client(attach_stacktrace=False, transport=events.append))