1515from decimal import Decimal
1616from functools import partial , partialmethod , wraps
1717from numbers import Real
18+ import traceback
1819from urllib .parse import parse_qs , unquote , urlencode , urlsplit , urlunsplit
1920
2021try :
@@ -737,6 +738,7 @@ def single_exception_from_error_tuple(
737738 exception_id = None , # type: Optional[int]
738739 parent_id = None , # type: Optional[int]
739740 source = None , # type: Optional[str]
741+ full_stack = None ,
740742):
741743 # type: (...) -> Dict[str, Any]
742744 """
@@ -807,6 +809,10 @@ def single_exception_from_error_tuple(
807809 ]
808810
809811 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
810816 exception_value ["stacktrace" ] = {"frames" : frames }
811817
812818 return exception_value
@@ -953,6 +959,7 @@ def exceptions_from_error_tuple(
953959 exc_info , # type: ExcInfo
954960 client_options = None , # type: Optional[Dict[str, Any]]
955961 mechanism = None , # type: Optional[Dict[str, Any]]
962+ full_stack = None ,
956963):
957964 # type: (...) -> List[Dict[str, Any]]
958965 exc_type , exc_value , tb = exc_info
@@ -970,14 +977,20 @@ def exceptions_from_error_tuple(
970977 mechanism = mechanism ,
971978 exception_id = 0 ,
972979 parent_id = 0 ,
980+ full_stack = full_stack ,
973981 )
974982
975983 else :
976984 exceptions = []
977985 for exc_type , exc_value , tb in walk_exception_chain (exc_info ):
978986 exceptions .append (
979987 single_exception_from_error_tuple (
980- exc_type , exc_value , tb , client_options , mechanism
988+ exc_type = exc_type ,
989+ exc_value = exc_value ,
990+ tb = tb ,
991+ client_options = client_options ,
992+ mechanism = mechanism ,
993+ full_stack = full_stack ,
981994 )
982995 )
983996
@@ -1104,12 +1117,13 @@ def event_from_exception(
11041117 # type: (...) -> Tuple[Event, Dict[str, Any]]
11051118 exc_info = exc_info_from_error (exc_info )
11061119 hint = event_hint_with_exc_info (exc_info )
1120+ full_stack = traceback .extract_stack ()
11071121 return (
11081122 {
11091123 "level" : "error" ,
11101124 "exception" : {
11111125 "values" : exceptions_from_error_tuple (
1112- exc_info , client_options , mechanism
1126+ exc_info , client_options , mechanism , full_stack
11131127 )
11141128 },
11151129 },
0 commit comments