8000 Stacktrace: Pass with_locals parameter. (#279) · etherscan-io/sentry-python@d25fba8 · GitHub
[go: up one dir, main page]

Skip to content

Commit d25fba8

Browse files
kobybumuntitaker
authored andcommitted
Stacktrace: Pass with_locals parameter. (getsentry#279)
* Stacktrace: Pass with_locals parameter. * fix: Formatting
1 parent 879467a commit d25fba8

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

sentry_sdk/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def _prepare_event(
118118
with capture_internal_exceptions():
119119
event["threads"] = [
120120
{
121-
"stacktrace": current_stacktrace(),
121+
"stacktrace": current_stacktrace(self.options["with_locals"]),
122122
"crashed": False,
123123
"current": True,
124124
}

sentry_sdk/integrations/logging.py

Copy file name to clipboard
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,13 @@ def _emit(self, record):
158158
return
159159

160160
hint = None # type: Optional[Dict[str, Any]]
161+
client_options = hub.client.options
161162

162163
# exc_info might be None or (None, None, None)
163164
if record.exc_info is not None and record.exc_info[0] is not None:
164165
event, hint = event_from_exception(
165166
record.exc_info,
166-
client_options=hub.client.options,
167+
client_options=client_options,
167168
mechanism={"type": "logging", "handled": True},
168169
)
169170
elif record.exc_info and record.exc_info[0] is None:
@@ -172,7 +173,7 @@ def _emit(self, record):
172173
with capture_internal_exceptions():
173174
event["threads"] = [
174175
{
175-
"stacktrace": current_stacktrace(),
176+
"stacktrace": current_stacktrace(client_options["with_locals"]),
176177
"crashed": False,
177178
"current": True,
178179
}

tests/test_client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,26 @@ def bar():
143143
assert functions[-2:] == ["foo", "bar"]
144144

145145

146+
def test_attach_stacktrace_enabled_no_locals():
147+
events = []
148+
hub = Hub(
149+
Client(attach_stacktrace=True, with_locals=False, transport=events.append)
150+
)
151+
152+
def foo():
153+
bar()
154+
155+
def bar():
156+
hub.capture_message("HI")
157+
158+
foo()
159+
160+
event, = events
161+
thread, = event["threads"]
162+
local_vars = [x.get("vars") for x in thread["stacktrace"]["frames"]]
163+
assert local_vars[-2:] == [None, None]
164+
165+
146166
def test_attach_stacktrace_disabled():
147167
events = []
148168
hub = Hub(Client(attach_stacktrace=False, transport=events.append))

0 commit comments

Comments
 (0)
0