Skip to content

Commit

Permalink
Stacktrace: Pass with_locals parameter. (#279)
Browse files Browse the repository at this point in the history
* Stacktrace: Pass with_locals parameter.

* fix: Formatting
  • Loading branch information
kobybum authored and untitaker committed Mar 5, 2019
1 parent 879467a commit d25fba8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
5 changes: 3 additions & 2 deletions sentry_sdk/integrations/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
}
Expand Down
20 changes: 20 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit d25fba8

Please sign in to comment.