1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 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"
|