def test_stack_trace_limit(elasticapm_client): def func(): 1 / 0 # I'm the context line of the last frame! try: list(get_me_more_test_frames(15, func)) except ZeroDivisionError: elasticapm_client.capture_exception() exception = elasticapm_client.events[ERROR][-1] frames = exception["exception"]["stacktrace"] assert len(frames) == 10 assert "I'm the context line of the last frame" in frames[-1][ "context_line"] elasticapm_client.config.update("1", stack_trace_limit=-1) try: list(get_me_more_test_frames(15, func)) except ZeroDivisionError: elasticapm_client.capture_exception() exception = elasticapm_client.events[ERROR][-1] frames = exception["exception"]["stacktrace"] assert len(frames) > 15 assert "I'm the context line of the last frame" in frames[-1][ "context_line"] elasticapm_client.config.update("1", stack_trace_limit=0) try: list(get_me_more_test_frames(15, func)) except ZeroDivisionError: elasticapm_client.capture_exception() exception = elasticapm_client.events[ERROR][-1] frames = exception["exception"]["stacktrace"] assert len(frames) == 0
def test_iter_stack_frames_max_frames_is_dynamic(elasticapm_client): def func(): with elasticapm.capture_span("yay"): pass elasticapm_client.begin_transaction("foo") get_me_more_test_frames(15, func=func) elasticapm_client.end_transaction() transaction = elasticapm_client.events[constants.TRANSACTION][0] span = elasticapm_client.spans_for_transaction(transaction)[0] assert len(span["stacktrace"]) == 10 elasticapm_client.config.update(version="2", stack_trace_limit=5) elasticapm_client.begin_transaction("foo") get_me_more_test_frames(15, func=func) elasticapm_client.end_transaction() transaction = elasticapm_client.events[constants.TRANSACTION][1] span = elasticapm_client.spans_for_transaction(transaction)[0] assert len(span["stacktrace"]) == 5
def test_iter_stack_frames_max_frames(): iterated_frames = list( stacks.iter_stack_frames(get_me_more_test_frames(10), config=Mock(stack_trace_limit=5))) assert len(iterated_frames) == 5 assert iterated_frames[4][0].f_locals["count"] == 5 iterated_frames = list( stacks.iter_stack_frames(get_me_more_test_frames(10), config=Mock(stack_trace_limit=-1))) assert len(iterated_frames) == 10 iterated_frames = list( stacks.iter_stack_frames(get_me_more_test_frames(10), config=Mock(stack_trace_limit=0))) assert len(iterated_frames) == 0 iterated_frames = list( stacks.iter_stack_frames(get_me_more_test_frames(10), skip=3, config=Mock(stack_trace_limit=5))) assert len(iterated_frames) == 5 assert iterated_frames[4][0].f_locals["count"] == 8
def test_iter_stack_frames_skip_frames(): frames = get_me_more_test_frames(4) iterated_frames = list(stacks.iter_stack_frames(frames, skip=3)) assert len(iterated_frames) == 1 assert iterated_frames[0][0].f_locals["count"] == 4