Skip to content

Commit 871c437

Browse files
authored
fix(profiling): Handle non frame types in profiler (#1965)
We've received report that occasionally, there's `AttributeError` on `f_back`. It's unclear what exactly causes this issue because the source of the frame is from a system libray. This avoids the `AttributeError` by wrapping the line in question with a `try ... except ...`. And whenever it does encounter this error, we should continue with what frames we have.
1 parent 439b3f7 commit 871c437

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

sentry_sdk/profiler.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from sentry_sdk._compat import PY33, PY311
2727
from sentry_sdk._types import TYPE_CHECKING
2828
from sentry_sdk.utils import (
29+
capture_internal_exception,
2930
filename_for_module,
3031
is_valid_sample_rate,
3132
logger,
@@ -252,8 +253,16 @@ def extract_stack(
252253
frames = deque(maxlen=max_stack_depth) # type: Deque[FrameType]
253254

254255
while frame is not None:
256+
try:
257+
f_back = frame.f_back
258+
except AttributeError:
259+
capture_internal_exception(sys.exc_info())
260+
# For some reason, the frame we got isn't a `FrameType` and doesn't
261+
# have a `f_back`. When this happens, we continue with any frames
262+
# that we've managed to extract up to this point.
263+
break
255264
frames.append(frame)
256-
frame = frame.f_back
265+
frame = f_back
257266

258267
if prev_cache is None:
259268
stack = tuple(extract_frame(frame, cwd) for frame in frames)

0 commit comments

Comments
 (0)