Skip to content

Commit 31d059c

Browse files
committed
Added full frames to full_stack
1 parent 3645218 commit 31d059c

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

sentry_sdk/utils.py

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ def single_exception_from_error_tuple(
738738
exception_id=None, # type: Optional[int]
739739
parent_id=None, # type: Optional[int]
740740
source=None, # type: Optional[str]
741-
full_stack=None,
741+
full_stack=None, # type: Optional[list[dict[str, Any]]]
742742
):
743743
# type: (...) -> Dict[str, Any]
744744
"""
@@ -809,43 +809,34 @@ def single_exception_from_error_tuple(
809809
]
810810

811811
if frames:
812-
# TODO: insert missing frames from full_stack into frames
813-
# elements of frames list look like this:
814-
# {'filename': 'main.py', 'abs_path': '/Users/antonpirker/code/testing-sentry/test-plain-python-missing-stack-frames/main.py', 'function': 'foo', 'module': '__main__', 'lineno': 19, 'pre_context': [' foo()', '', '', 'def foo():', ' try:'], 'context_line': ' bar()', 'post_context': [' except Exception as e:', ' capture_exception(e)', '', '', 'def bar():'], 'vars': {'e': "Exception('1 some exception')"}}
815-
# elements of full_stack are instances of type FrameSummary
816-
817-
full_stack.reverse()
818-
frames.reverse()
819-
820-
for stackframe in full_stack:
821-
stackframe_id = {
822-
"filename": stackframe["abs_path"],
823-
"line": stackframe["context_line"],
824-
"lineno": stackframe["lineno"],
825-
"name": stackframe["function"],
812+
if not full_stack:
813+
new_frames = frames
814+
else:
815+
# Add the missing frames from full_stack
816+
frame_ids = {
817+
(
818+
frame["abs_path"],
819+
frame["context_line"],
820+
frame["lineno"],
821+
frame["function"],
822+
)
823+
for frame in frames
826824
}
827825

828-
found = False
829-
for frame in frames:
830-
frame_id = {
831-
"filename": frame["abs_path"],
832-
"line": frame["context_line"],
833-
"lineno": frame["lineno"],
834-
"name": frame["function"],
835-
}
836-
837-
if stackframe_id == frame_id:
838-
found = True
839-
break
840-
841-
if not found:
842-
frames.append(stackframe)
843-
844-
frames.reverse()
845-
from pprint import pprint
826+
new_frames = [
827+
stackframe
828+
for stackframe in full_stack
829+
if (
830+
stackframe["abs_path"],
831+
stackframe["context_line"],
832+
stackframe["lineno"],
833+
stackframe["function"],
834+
)
835+
not in frame_ids
836+
]
837+
new_frames.extend(frames)
846838

847-
pprint(frames)
848-
exception_value["stacktrace"] = {"frames": frames}
839+
exception_value["stacktrace"] = {"frames": new_frames}
849840

850841
return exception_value
851842

@@ -900,6 +891,7 @@ def exceptions_from_error(
900891
exception_id=0, # type: int
901892
parent_id=0, # type: int
902893
source=None, # type: Optional[str]
894+
full_stack=None, # type: Optional[list[dict[str, Any]]]
903895
):
904896
# type: (...) -> Tuple[int, List[Dict[str, Any]]]
905897
"""
@@ -919,6 +911,7 @@ def exceptions_from_error(
919911
exception_id=exception_id,
920912
parent_id=parent_id,
921913
source=source,
914+
full_stack=full_stack,
922915
)
923916
exceptions = [parent]
924917

@@ -944,6 +937,7 @@ def exceptions_from_error(
944937
mechanism=mechanism,
945938
exception_id=exception_id,
946939
source="__cause__",
940+
full_stack=full_stack,
947941
)
948942
exceptions.extend(child_exceptions)
949943

@@ -965,6 +959,7 @@ def exceptions_from_error(
965959
mechanism=mechanism,
966960
exception_id=exception_id,
967961
source="__context__",
962+
full_stack=full_stack,
968963
)
969964
exceptions.extend(child_exceptions)
970965

@@ -981,6 +976,7 @@ def exceptions_from_error(
981976
exception_id=exception_id,
982977
parent_id=parent_id,
983978
source="exceptions[%s]" % idx,
979+
full_stack=full_stack,
984980
)
985981
exceptions.extend(child_exceptions)
986982

@@ -991,7 +987,7 @@ def exceptions_from_error_tuple(
991987
exc_info, # type: ExcInfo
992988
client_options=None, # type: Optional[Dict[str, Any]]
993989
mechanism=None, # type: Optional[Dict[str, Any]]
994-
full_stack=None,
990+
full_stack=None, # type: Optional[list[dict[str, Any]]]
995991
):
996992
# type: (...) -> List[Dict[str, Any]]
997993
exc_type, exc_value, tb = exc_info
@@ -1154,6 +1150,9 @@ def get_full_stack():
11541150
_, _, tb = sys.exc_info()
11551151

11561152
# Get the frame one level up (skipping this function's frame)
1153+
if tb is None:
1154+
return []
1155+
11571156
frame = tb.tb_frame.f_back
11581157

11591158
stack_info = []

0 commit comments

Comments
 (0)