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

feat(tracer): add Python 3.11 support #4125

Merged
merged 79 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
9070cdf
Added Py 3.11 to Riot, added version check for PyFloat_Pack8(), tempo…
Yun-Kim Aug 22, 2022
1c29dff
Reverted 3.11 version pin in dockerfile, removed unnecessary comment …
Yun-Kim Aug 23, 2022
f1c0af5
Reverse condition
Yun-Kim Aug 23, 2022
20c705a
Merge branch '1.x' into yun-kim/py311
Yun-Kim Aug 23, 2022
d96a4c9
Made collector/stack.pyx 3.11 compatible
Yun-Kim Aug 25, 2022
77e4d17
Uncommented Appsec setup
Yun-Kim Aug 25, 2022
508d5c6
Merge branch '1.x' into yun-kim/py311
Yun-Kim Aug 25, 2022
f8f62c1
Typos
Yun-Kim Sep 15, 2022
0fa9bff
Merge branch '1.x' into yun-kim/py311
Yun-Kim Sep 15, 2022
ac33541
Exclude python 3.11 for internal/debugger/graphql/graphene since they…
Yun-Kim Sep 20, 2022
2193159
Merge branch '1.x' into yun-kim/py311
Yun-Kim Sep 21, 2022
d08e99b
Add none check for exceptions in stack collector
Yun-Kim Sep 22, 2022
c7eddc9
Merge branch '1.x' into yun-kim/py311
Yun-Kim Sep 22, 2022
e5a1cba
Pinned cherrypy, pynamodb, django, mariadb test suite Python versions
Yun-Kim Sep 23, 2022
28708f6
Pinned python version for psycopg test suite
Yun-Kim Sep 23, 2022
d3ba946
Update grpc test suites for python 3.11
Yun-Kim Sep 23, 2022
a5d2aa1
Fixed Starlette test app for Py 3.11
Yun-Kim Sep 23, 2022
f7fd78b
Disable aioredis tests for Python 3.11
Yun-Kim Sep 23, 2022
bf0b7c9
Remove gevent as dependency of ddtracerun tests
Yun-Kim Sep 26, 2022
086d157
Separate ddtracerun test suite into pre-3.11 and post-3.11, skip geve…
Yun-Kim Sep 26, 2022
de7fa2e
Added py 3.11 test suites into tox
Yun-Kim Sep 26, 2022
aad8d6f
Pinned dogpile version in tox, reformatted riot testsuites for grpc
Yun-Kim Sep 26, 2022
fcd1311
Merge branch '1.x' into yun-kim/py311
Yun-Kim Sep 26, 2022
a4f1f1b
Merge branch '1.x' into yun-kim/py311
Yun-Kim Sep 27, 2022
5a6d9b7
Merge branch '1.x' into yun-kim/py311
Yun-Kim Sep 27, 2022
cdd1ccf
Added dogpile==1.1 to tox
Yun-Kim Sep 27, 2022
d8a6b88
Merge branch '1.x' into yun-kim/py311
Yun-Kim Sep 28, 2022
e2f0727
Unpin debugger, pin asyncpg
Yun-Kim Sep 28, 2022
a752988
Pin vine dependency for kombu python 3.11 tests, repin debugger tests
Yun-Kim Sep 29, 2022
1d0993f
Upgraded kombu tests to run Python 3.11 with kombu >= 5.0
Yun-Kim Sep 29, 2022
d5460ce
Unpin hypothesis
Yun-Kim Sep 30, 2022
146db8e
Pin hypothesis to 6.55
Yun-Kim Sep 30, 2022
8a1f245
Merge branch '1.x' into yun-kim/py311
Yun-Kim Oct 3, 2022
4e0b8ff
Merge branch '1.x' into yun-kim/py311
Yun-Kim Oct 3, 2022
02a25d9
Unpin hypothesis
Yun-Kim Oct 3, 2022
9bb5161
Separate test_http.py tracer test suite from riot to tox
Yun-Kim Oct 4, 2022
13c826d
Merge branch '1.x' into yun-kim/py311
Yun-Kim Oct 4, 2022
253f1d9
Add tracer test_http test suite into circleci config
Yun-Kim Oct 4, 2022
67bde40
Add pys for test_http test suite in tox
Yun-Kim Oct 4, 2022
fb52184
Remove closing regex for circleci tracer test_http job
Yun-Kim Oct 4, 2022
6d7c004
Try different pattern
Yun-Kim Oct 4, 2022
6219277
Merge branch '1.x' into yun-kim/py311
Yun-Kim Oct 5, 2022
8f7e7cb
Merge riot tracer test suites
Yun-Kim Oct 5, 2022
a1e1e79
Merge branch '1.x' into yun-kim/py311
Yun-Kim Oct 6, 2022
b69ddaa
Merge branch '1.x' into yun-kim/py311
Yun-Kim Oct 14, 2022
4d81ce7
Remove celery tests for python 3.11 until billiard dependency compatible
Yun-Kim Oct 14, 2022
3e39392
Replace removed inspect function with py 3.11 compatible function
Yun-Kim Oct 14, 2022
3a5b3ee
Updated starlette and fasapi test suites to use python 3.11 compatibl…
Yun-Kim Oct 17, 2022
bc5b544
Remove gevent tests with Python 3.11
Yun-Kim Oct 17, 2022
39450f6
Merge branch '1.x' into yun-kim/py311
Yun-Kim Oct 18, 2022
91b96d4
Merge branch '1.x' into yun-kim/py311
Yun-Kim Oct 18, 2022
0693351
Replace comment in riotfile
Yun-Kim Oct 18, 2022
c70c42b
Revert profiler changes
Yun-Kim Oct 20, 2022
f41a26a
Re-add profiler changes to allow profiler to compile in py311
Yun-Kim Oct 20, 2022
c806dbe
Merge branch '1.x' into yun-kim/py311
Yun-Kim Oct 20, 2022
b9b8fa7
Remove grpc_aio tests with 3.11
Yun-Kim Oct 20, 2022
72d99e8
Address comments
Yun-Kim Oct 20, 2022
45bfb7d
Skip bytecode related tests
Kyle-Verhoog Oct 21, 2022
45bd4c3
Skip py36 wrapping tests as well
Kyle-Verhoog Oct 21, 2022
aa55193
Skip internal gevent test
Kyle-Verhoog Oct 21, 2022
f41db8f
Merge branch '1.x' into yun-kim/py311
Kyle-Verhoog Oct 21, 2022
c167e49
Merge branch '1.x' into yun-kim/py311
Yun-Kim Oct 24, 2022
d20a8bf
Address comments, update changelog
Yun-Kim Oct 24, 2022
33fbdfb
Revert removing py27 from black target_version, capitalize changelog …
Yun-Kim Oct 24, 2022
521695b
Remove 3.10 from opentracer gevent tests tox
Yun-Kim Oct 24, 2022
a291b93
Disable profiler and dynamic instrumentation if running with Python 3.11
Yun-Kim Oct 24, 2022
3187689
Remove gevent skips as gevent 22.8 is compatible with Python 3.11
Yun-Kim Oct 25, 2022
922dedf
Update changelog, add whitespace to comment
Yun-Kim Oct 25, 2022
de9d63f
Pin grpcio to 1.49 for Python 3.11
Yun-Kim Oct 25, 2022
e4649c0
Fix skip in grpc_aio with Python 3.11
Yun-Kim Oct 25, 2022
35d0318
Merge branch '1.x' into yun-kim/py311
Kyle-Verhoog Oct 25, 2022
244da69
Merge branch '1.x' into yun-kim/py311
Kyle-Verhoog Oct 25, 2022
49f1a2e
Skip additional segfaulting grpc_aio tests
Kyle-Verhoog Oct 25, 2022
a848af6
Merge branch '1.x' into yun-kim/py311
Yun-Kim Oct 25, 2022
92c2742
Remove unsupported version of pynamodb for python 3.11 test suite
Yun-Kim Oct 25, 2022
e491de5
Merge branch '1.x' into yun-kim/py311
mergify[bot] Oct 26, 2022
e5a926b
Merge branch '1.x' into yun-kim/py311
mergify[bot] Oct 26, 2022
3caf622
Merge branch '1.x' into yun-kim/py311
mergify[bot] Oct 26, 2022
7079b38
Merge branch '1.x' into yun-kim/py311
mergify[bot] Oct 26, 2022
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
6 changes: 5 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ jobs:
steps:
- run_test:
pattern: "tracer"
- run_tox_scenario:
Yun-Kim marked this conversation as resolved.
Show resolved Hide resolved
# Riot venvs break with Py 3.11 importlib, specifically with hypothesis (test_http.py).
# We skip the test_http.py tests in riot and run the test_http.py tests through tox.
pattern: '^py.\+-tracer_test_http'

telemetry:
<<: *machine_executor
Expand All @@ -419,7 +423,7 @@ jobs:
parallelism: 7
steps:
- run_tox_scenario:
pattern: '^py..-opentracer'
pattern: '^py.\+-opentracer'
Kyle-Verhoog marked this conversation as resolved.
Show resolved Hide resolved

# Building gevent (for which we never want wheels because they crash)
# on Python 2.7 requires Microsoft Visual C++ 9.0 which is not installed. :(
Expand Down
5 changes: 5 additions & 0 deletions ddtrace/debugging/_debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ class Debugger(Service):
def enable(cls, run_module=False):
# type: (bool) -> None
"""Enable the debugger (idempotent)."""
if sys.version_info >= (3, 11, 0):
raise RuntimeError(
majorgreys marked this conversation as resolved.
Show resolved Hide resolved
"Dynamic Instrumentation is not yet compatible with Python 3.11. "
"See tracking issue for more details: https://github.com/DataDog/dd-trace-py/issues/4149"
)
if cls._instance is not None:
log.debug("%s already enabled", cls.__name__)
return
Expand Down
7 changes: 6 additions & 1 deletion ddtrace/internal/pack_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,12 @@ static inline int msgpack_pack_double(msgpack_packer* x, double d)
{
unsigned char buf[9];
buf[0] = 0xcb;
_PyFloat_Pack8(d, &buf[1], 0);
// Python 3.11 introduced PyFloat_Pack8() to the public C API and moved _PyFloat_Pack8() to the internal C API
#if PY_VERSION_HEX <= 0x030B0000
_PyFloat_Pack8(d, &buf[1], 0);
#else
PyFloat_Pack8(d, &buf[1], 0);
#endif
msgpack_pack_append_buffer(x, buf, 9);
}

Expand Down
41 changes: 30 additions & 11 deletions ddtrace/profiling/collector/stack.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,17 @@ IF UNAME_SYSNAME != "Windows" and PY_MAJOR_VERSION >= 3 and PY_MINOR_VERSION >=

_PyErr_StackItem * _PyErr_GetTopmostException(PyThreadState *tstate)

ctypedef struct _PyErr_StackItem:
PyObject* exc_type
PyObject* exc_value
PyObject* exc_traceback
IF PY_MINOR_VERSION < 11:
ctypedef struct _PyErr_StackItem:
PyObject* exc_type
PyObject* exc_value
PyObject* exc_traceback
ELSE:
ctypedef struct _PyErr_StackItem:
PyObject* exc_value

PyObject* PyException_GetTraceback(PyObject* exc)
PyObject* Py_TYPE(PyObject* ob)

IF PY_MINOR_VERSION == 7:
# Python 3.7
Expand Down Expand Up @@ -198,6 +205,8 @@ IF UNAME_SYSNAME != "Windows" and PY_MAJOR_VERSION >= 3 and PY_MINOR_VERSION >=
# Needed for accessing _PyGC_FINALIZED when we build with -DPy_BUILD_CORE
cdef extern from "<internal/pycore_gc.h>":
pass
cdef extern from "<Python.h>":
PyObject* PyThreadState_GetFrame(PyThreadState* tstate)
ELSE:
from cpython.ref cimport Py_DECREF

Expand All @@ -214,7 +223,8 @@ cdef collect_threads(thread_id_ignore_list, thread_time, thread_span_links) with
cdef PyThreadState* tstate
cdef _PyErr_StackItem* exc_info
cdef PyThread_type_lock lmutex = _PyRuntime.interpreters.mutex

cdef PyObject* exc_type
cdef PyObject* exc_tb
cdef dict running_threads = {}

# This is an internal lock but we do need it.
Expand All @@ -230,13 +240,22 @@ cdef collect_threads(thread_id_ignore_list, thread_time, thread_span_links) with
tstate = PyInterpreterState_ThreadHead(interp)
while tstate:
# The frame can be NULL
if tstate.frame:
running_threads[tstate.thread_id] = <object>tstate.frame

# 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:
Kyle-Verhoog marked this conversation as resolved.
Show resolved Hide resolved
frame = PyThreadState_GetFrame(tstate)
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_type and exc_info.exc_traceback:
current_exceptions[tstate.thread_id] = (<object>exc_info.exc_type, <object>exc_info.exc_traceback)

if exc_info and exc_info.exc_value:
Yun-Kim marked this conversation as resolved.
Show resolved Hide resolved
# 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)
tstate = PyThreadState_Next(tstate)

interp = PyInterpreterState_Next(interp)
Expand Down
6 changes: 6 additions & 0 deletions ddtrace/profiling/profiler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
import logging
import os
import sys
import typing
from typing import List
from typing import Optional
Expand Down Expand Up @@ -57,6 +58,11 @@ def start(self, stop_on_exit=True, profile_children=True):
:param profile_children: Whether to start a profiler in child processes.
"""

if sys.version_info >= (3, 11, 0):
raise RuntimeError(
"Profiling is not yet compatible with Python 3.11. "
"See tracking issue for more details: https://github.com/DataDog/dd-trace-py/issues/4149"
)
if profile_children:
try:
uwsgi.check_uwsgi(self._restart_on_fork, atexit=self.stop if stop_on_exit else None)
Expand Down
6 changes: 3 additions & 3 deletions docs/versioning.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ Supported runtimes
* - Linux
- x86-64, i686, AArch64
- CPython
- 2.7, 3.5-3.10
- 2.7, 3.5-3.11
- ``<2``
* - MacOS
- Intel, Apple Silicon
- CPython
- 2.7, 3.5-3.10
- 2.7, 3.5-3.11
- ``<2``
* - Windows
- 64bit, 32bit
- CPython
- 2.7, 3.5-3.10
- 2.7, 3.5-3.11
- ``<2``
10 changes: 10 additions & 0 deletions releasenotes/notes/python311-tracer-a7077c0e461622d2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
prelude: >
Initial library support has been added for Python 3.11. Continuous Profiler and Dynamic Instrumentation are not yet compatible and must be disabled in order to use the library with Python 3.11. Support for Continuous Profiler and Dynamic Instrumentation will be added in a future release.
For full Python 3.11 support status please see: https://github.com/DataDog/dd-trace-py/issues/4149
features:
- |
tracer: added support for Python 3.11.
Yun-Kim marked this conversation as resolved.
Show resolved Hide resolved
Yun-Kim marked this conversation as resolved.
Show resolved Hide resolved
upgrade:
- |
Python 3.11: Continuous Profiler and Dynamic Instrumentation must be disabled as they do not current support Python 3.11.
Loading