Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(profiler): version gate python 3.11 changes to stack collector (backport #4448) #4452

Merged
merged 3 commits into from
Nov 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions ddtrace/profiling/collector/stack.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,26 @@ cdef collect_threads(thread_id_ignore_list, thread_time, thread_span_links) with
tstate = PyInterpreterState_ThreadHead(interp)
while tstate:
# The frame can be NULL
# Python 3.9 added helper function to public C API to access PyFrameObject from tstate,
# Python 3.11 moved PyFrameObject to internal C API and cannot be directly accessed from tstate
IF PY_MINOR_VERSION >= 9:
IF PY_MINOR_VERSION >= 11:
frame = PyThreadState_GetFrame(tstate)
if frame:
running_threads[tstate.thread_id] = <object>frame
exc_info = _PyErr_GetTopmostException(tstate)
if exc_info and exc_info.exc_value:
# Python 3.11 removed exc_type, exc_traceback from exception representations,
# can instead derive exc_type and exc_traceback from remaining exc_value field
exc_type = Py_TYPE(exc_info.exc_value)
exc_tb = PyException_GetTraceback(exc_info.exc_value)
if exc_type and exc_tb:
current_exceptions[tstate.thread_id] = (<object>exc_type, <object>exc_tb)
ELSE:
frame = tstate.frame
if frame:
running_threads[tstate.thread_id] = <object>frame
exc_info = _PyErr_GetTopmostException(tstate)
if exc_info and exc_info.exc_value:
# Python 3.11 removed exc_type, exc_traceback from exception representations, can instead
# derive exc_type and exc_traceback from remaining exc_value field
exc_type = Py_TYPE(exc_info.exc_value)
exc_tb = PyException_GetTraceback(exc_info.exc_value)
if exc_type and exc_tb:
current_exceptions[tstate.thread_id] = (<object>exc_type, <object>exc_tb)
if frame:
running_threads[tstate.thread_id] = <object>frame
exc_info = _PyErr_GetTopmostException(tstate)
if exc_info and exc_info.exc_type and exc_info.exc_traceback:
current_exceptions[tstate.thread_id] = (<object>exc_info.exc_type, <object>exc_info.exc_traceback)
tstate = PyThreadState_Next(tstate)

interp = PyInterpreterState_Next(interp)
Expand Down