-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new `init()` option `add_full_stack` (default `False`), when set to `True` it will add all the missing frames from the beginning of the execution to the stack trace sent to Sentry. Also adds another option `max_stack_frames` (default `100`) to limit the number of frames sent. The limitation is only enforced when `add_full_stack=True` to not change behavior for existing users. Fixes #3646
- Loading branch information
1 parent
50ad148
commit cda5127
Showing
3 changed files
with
185 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import sentry_sdk | ||
|
||
|
||
def test_full_stack_frames_default(sentry_init, capture_events): | ||
sentry_init() | ||
events = capture_events() | ||
|
||
def foo(): | ||
try: | ||
bar() | ||
except Exception as e: | ||
sentry_sdk.capture_exception(e) | ||
|
||
def bar(): | ||
raise Exception("This is a test exception") | ||
|
||
foo() | ||
|
||
(event,) = events | ||
frames = event["exception"]["values"][0]["stacktrace"]["frames"] | ||
|
||
assert len(frames) == 2 | ||
assert frames[-1]["function"] == "bar" | ||
assert frames[-2]["function"] == "foo" | ||
|
||
|
||
def test_full_stack_frames_enabled(sentry_init, capture_events): | ||
sentry_init( | ||
add_full_stack=True, | ||
) | ||
events = capture_events() | ||
|
||
def foo(): | ||
try: | ||
bar() | ||
except Exception as e: | ||
sentry_sdk.capture_exception(e) | ||
|
||
def bar(): | ||
raise Exception("This is a test exception") | ||
|
||
foo() | ||
|
||
(event,) = events | ||
frames = event["exception"]["values"][0]["stacktrace"]["frames"] | ||
|
||
assert len(frames) > 2 | ||
assert frames[-1]["function"] == "bar" | ||
assert frames[-2]["function"] == "foo" | ||
assert frames[-3]["function"] == "foo" | ||
assert frames[-4]["function"] == "test_full_stack_frames_enabled" | ||
|
||
|
||
def test_full_stack_frames_enabled_truncated(sentry_init, capture_events): | ||
sentry_init( | ||
add_full_stack=True, | ||
max_stack_frames=3, | ||
) | ||
events = capture_events() | ||
|
||
def foo(): | ||
try: | ||
bar() | ||
except Exception as e: | ||
sentry_sdk.capture_exception(e) | ||
|
||
def bar(): | ||
raise Exception("This is a test exception") | ||
|
||
foo() | ||
|
||
(event,) = events | ||
frames = event["exception"]["values"][0]["stacktrace"]["frames"] | ||
|
||
assert len(frames) == 3 | ||
assert frames[-1]["function"] == "bar" | ||
assert frames[-2]["function"] == "foo" | ||
assert frames[-3]["function"] == "foo" | ||
|
||
|
||
def test_full_stack_frames_default_no_truncation_happening(sentry_init, capture_events): | ||
sentry_init( | ||
max_stack_frames=1, # this is ignored if add_full_stack=False (which is the default) | ||
) | ||
events = capture_events() | ||
|
||
def foo(): | ||
try: | ||
bar() | ||
except Exception as e: | ||
sentry_sdk.capture_exception(e) | ||
|
||
def bar(): | ||
raise Exception("This is a test exception") | ||
|
||
foo() | ||
|
||
(event,) = events | ||
frames = event["exception"]["values"][0]["stacktrace"]["frames"] | ||
|
||
assert len(frames) == 2 | ||
assert frames[-1]["function"] == "bar" | ||
assert frames[-2]["function"] == "foo" |