@@ -806,7 +806,7 @@ def single_exception_from_error_tuple(
806
806
custom_repr = custom_repr ,
807
807
)
808
808
for tb in iter_stacks (tb )
809
- ]
809
+ ] # type: List[Dict[str, Any]]
810
810
811
811
if frames :
812
812
if not full_stack :
@@ -836,6 +836,13 @@ def single_exception_from_error_tuple(
836
836
]
837
837
new_frames .extend (frames )
838
838
839
+ # Limit the number of frames
840
+ max_stack_frames = (
841
+ client_options .get ("max_stack_frames" ) if client_options else None
842
+ )
843
+ if max_stack_frames is not None :
844
+ new_frames = new_frames [:max_stack_frames ]
845
+
839
846
exception_value ["stacktrace" ] = {"frames" : new_frames }
840
847
841
848
return exception_value
@@ -1142,22 +1149,10 @@ def get_full_stack():
1142
1149
"""
1143
1150
Returns a serialized representation of the full stack from the first frame that is not in sentry_sdk.
1144
1151
"""
1145
- try :
1146
- # Raise an exception to capture the current stack
1147
- raise Exception
1148
- except :
1149
- # Get the current stack frame
1150
- _ , _ , tb = sys .exc_info ()
1151
-
1152
- # Get the frame one level up (skipping this function's frame)
1153
- if tb is None :
1154
- return []
1155
-
1156
- frame = tb .tb_frame .f_back
1157
-
1158
1152
stack_info = []
1159
1153
1160
1154
# Walk up the stack
1155
+ frame = sys ._getframe (1 ) # type: Optional[FrameType]
1161
1156
while frame :
1162
1157
in_sdk = False
1163
1158
try :
@@ -1184,11 +1179,11 @@ def event_from_exception(
1184
1179
# type: (...) -> Tuple[Event, Dict[str, Any]]
1185
1180
exc_info = exc_info_from_error (exc_info )
1186
1181
hint = event_hint_with_exc_info (exc_info )
1187
- full_stack = get_full_stack ()
1188
1182
1189
- # TODO: add an option "add_full_stack" to the client options to add the full stack to the event (defaults to True)
1190
-
1191
- # TODO: add an option "max_stack_frames" to the client options to limit the number of stack frames (defaults to 50?)
1183
+ if client_options and client_options ["add_full_stack" ]:
1184
+ full_stack = get_full_stack ()
1185
+ else :
1186
+ full_stack = None
1192
1187
1193
1188
return (
1194
1189
{
0 commit comments