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(pymongo): add support for v4.9 #10718

Merged
merged 11 commits into from
Sep 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/13fc59d.in
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/10a00e7.in
#
attrs==24.2.0
coverage[toml]==7.6.1
Expand All @@ -11,12 +11,12 @@ exceptiongroup==1.2.2
hypothesis==6.45.0
iniconfig==2.0.0
mock==5.1.0
mongoengine==0.28.2
mongoengine==0.29.1
opentracing==2.4.0
packaging==24.1
pluggy==1.5.0
pymongo==4.8.0
pytest==8.3.2
pytest==8.3.3
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/63c9090.in
# pip-compile --no-annotate .riot/requirements/1424e42.in
#
attrs==24.2.0
coverage[toml]==7.6.1
dnspython==2.6.1
hypothesis==6.45.0
iniconfig==2.0.0
mock==5.1.0
mongoengine==0.28.2
mongoengine==0.29.1
opentracing==2.4.0
packaging==24.1
pluggy==1.5.0
pymongo==4.8.0
pytest==8.3.2
pytest==8.3.3
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/9627328.in
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/14e85f3.in
#
attrs==24.2.0
coverage[toml]==7.6.1
dnspython==2.6.1
hypothesis==6.45.0
iniconfig==2.0.0
mock==5.1.0
mongoengine==0.28.2
mongoengine==0.29.1
opentracing==2.4.0
packaging==24.1
pluggy==1.5.0
pymongo==4.8.0
pytest==8.3.2
pytest==8.3.3
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.7
# by the following command:
#
# pip-compile --allow-unsafe --config=pyproject.toml --no-annotate --resolver=backtracking .riot/requirements/c998f1e.in
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/16cae33.in
#
attrs==24.2.0
coverage[toml]==7.2.7
Expand All @@ -12,7 +12,7 @@ hypothesis==6.45.0
importlib-metadata==6.7.0
iniconfig==2.0.0
mock==5.1.0
mongoengine==0.28.2
mongoengine==0.29.1
opentracing==2.4.0
packaging==24.0
pluggy==1.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/14fb6c4.in
# pip-compile --no-annotate .riot/requirements/1ce9a99.in
#
attrs==24.2.0
coverage[toml]==7.6.1
dnspython==2.6.1
exceptiongroup==1.2.2
hypothesis==6.45.0
importlib-metadata==8.4.0
importlib-metadata==8.5.0
iniconfig==2.0.0
mock==5.1.0
mongoengine==0.28.2
mongoengine==0.29.1
opentracing==2.4.0
packaging==24.1
pluggy==1.5.0
pymongo==4.8.0
pytest==8.3.2
pytest==8.3.3
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
sortedcontainers==2.4.0
tomli==2.0.1
zipp==3.20.1
zipp==3.20.2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.7
# by the following command:
#
# pip-compile --allow-unsafe --config=pyproject.toml --no-annotate --resolver=backtracking .riot/requirements/16d0967.in
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/1ed6ce0.in
#
attrs==24.2.0
coverage[toml]==7.2.7
Expand All @@ -12,7 +12,7 @@ hypothesis==6.45.0
importlib-metadata==6.7.0
iniconfig==2.0.0
mock==5.1.0
mongoengine==0.28.2
mongoengine==0.29.1
opentracing==2.4.0
packaging==24.0
pluggy==1.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/f97f8c0.in
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/328b28c.in
#
attrs==24.2.0
coverage[toml]==7.6.1
Expand All @@ -11,12 +11,12 @@ exceptiongroup==1.2.2
hypothesis==6.45.0
iniconfig==2.0.0
mock==5.1.0
mongoengine==0.28.2
mongoengine==0.29.1
opentracing==2.4.0
packaging==24.1
pluggy==1.5.0
pymongo==4.8.0
pytest==8.3.2
pytest==8.3.3
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/182cbd0.in
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/ad40916.in
#
attrs==24.2.0
coverage[toml]==7.6.1
dnspython==2.6.1
hypothesis==6.45.0
iniconfig==2.0.0
mock==5.1.0
mongoengine==0.28.2
mongoengine==0.29.1
opentracing==2.4.0
packaging==24.1
pluggy==1.5.0
pymongo==4.8.0
pytest==8.3.2
pytest==8.3.3
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/541b4d9.in
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/b089663.in
#
attrs==24.2.0
coverage[toml]==7.6.1
dnspython==2.6.1
exceptiongroup==1.2.2
hypothesis==6.45.0
importlib-metadata==8.4.0
importlib-metadata==8.5.0
iniconfig==2.0.0
mock==5.1.0
mongoengine==0.28.2
mongoengine==0.29.1
opentracing==2.4.0
packaging==24.1
pluggy==1.5.0
pymongo==4.8.0
pytest==8.3.2
pytest==8.3.3
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
sortedcontainers==2.4.0
tomli==2.0.1
zipp==3.20.1
zipp==3.20.2
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/172570f.in
# pip-compile --no-annotate .riot/requirements/b344fed.in
#
attrs==24.2.0
coverage[toml]==7.6.1
dnspython==2.6.1
hypothesis==6.45.0
iniconfig==2.0.0
mock==5.1.0
mongoengine==0.28.2
mongoengine==0.29.1
opentracing==2.4.0
packaging==24.1
pluggy==1.5.0
pymongo==4.8.0
pytest==8.3.2
pytest==8.3.3
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/1dad05b.in
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/de53117.in
#
attrs==24.2.0
coverage[toml]==7.6.1
dnspython==2.6.1
exceptiongroup==1.2.2
hypothesis==6.45.0
importlib-metadata==8.4.0
importlib-metadata==8.5.0
iniconfig==2.0.0
mock==5.1.0
mongoengine==0.28.2
mongoengine==0.29.1
opentracing==2.4.0
packaging==24.1
pluggy==1.5.0
pymongo==4.8.0
pytest==8.3.2
pytest==8.3.3
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
sortedcontainers==2.4.0
tomli==2.0.1
zipp==3.20.1
zipp==3.20.2
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/178ae92.in
# pip-compile --no-annotate .riot/requirements/f9d0e8e.in
#
attrs==24.2.0
coverage[toml]==7.6.1
dnspython==2.6.1
exceptiongroup==1.2.2
hypothesis==6.45.0
importlib-metadata==8.4.0
importlib-metadata==8.5.0
iniconfig==2.0.0
mock==5.1.0
mongoengine==0.28.2
mongoengine==0.29.1
opentracing==2.4.0
packaging==24.1
pluggy==1.5.0
pymongo==4.8.0
pytest==8.3.2
pytest==8.3.3
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
sortedcontainers==2.4.0
tomli==2.0.1
zipp==3.20.1
zipp==3.20.2
55 changes: 32 additions & 23 deletions ddtrace/contrib/internal/pymongo/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@
from .client import set_address_tags


_VERSION = pymongo.version_tuple

if _VERSION >= (4, 9):
from pymongo.synchronous.pool import Connection
from pymongo.synchronous.server import Server
from pymongo.synchronous.topology import Topology
elif _VERSION >= (4, 5):
from pymongo.pool import Connection
from pymongo.server import Server
from pymongo.topology import Topology
else:
from pymongo.pool import SocketInfo as Connection
from pymongo.server import Server
from pymongo.topology import Topology


_CHECKOUT_FN_NAME = "get_socket" if pymongo.version_tuple < (4, 5) else "checkout"


Expand All @@ -41,9 +57,6 @@ def get_version():
return getattr(pymongo, "__version__", "")


_VERSION = pymongo.version_tuple


def patch():
if getattr(pymongo, "_datadog_patch", False):
return
Expand All @@ -60,43 +73,39 @@ def unpatch():

def patch_pymongo_module():
_w(pymongo.MongoClient.__init__, _trace_mongo_client_init)
_w(pymongo.topology.Topology.select_server, _trace_topology_select_server)
_w(Topology.select_server, _trace_topology_select_server)
quinna-h marked this conversation as resolved.
Show resolved Hide resolved
if _VERSION >= (3, 12):
_w(pymongo.server.Server.run_operation, _trace_server_run_operation_and_with_response)
_w(Server.run_operation, _trace_server_run_operation_and_with_response)
elif _VERSION >= (3, 9):
_w(pymongo.server.Server.run_operation_with_response, _trace_server_run_operation_and_with_response)
_w(Server.run_operation_with_response, _trace_server_run_operation_and_with_response)
else:
_w(pymongo.server.Server.send_message_with_response, _trace_server_send_message_with_response)
_w(Server.send_message_with_response, _trace_server_send_message_with_response)

if _VERSION >= (4, 5):
_w(pymongo.server.Server.checkout, traced_get_socket)
_w(pymongo.pool.Connection.command, _trace_socket_command)
_w(pymongo.pool.Connection.write_command, _trace_socket_write_command)
_w(Server.checkout, traced_get_socket)
else:
_w(pymongo.server.Server.get_socket, traced_get_socket)
_w(pymongo.pool.SocketInfo.command, _trace_socket_command)
_w(pymongo.pool.SocketInfo.write_command, _trace_socket_write_command)
_w(Server.get_socket, traced_get_socket)
_w(Connection.command, _trace_socket_command)
_w(Connection.write_command, _trace_socket_write_command)


def unpatch_pymongo_module():
_u(pymongo.MongoClient.__init__, _trace_mongo_client_init)
_u(pymongo.topology.Topology.select_server, _trace_topology_select_server)
_u(Topology.select_server, _trace_topology_select_server)

if _VERSION >= (3, 12):
_u(pymongo.server.Server.run_operation, _trace_server_run_operation_and_with_response)
_u(Server.run_operation, _trace_server_run_operation_and_with_response)
elif _VERSION >= (3, 9):
_u(pymongo.server.Server.run_operation_with_response, _trace_server_run_operation_and_with_response)
_u(Server.run_operation_with_response, _trace_server_run_operation_and_with_response)
else:
_u(pymongo.server.Server.send_message_with_response, _trace_server_send_message_with_response)
_u(Server.send_message_with_response, _trace_server_send_message_with_response)

if _VERSION >= (4, 5):
_u(pymongo.server.Server.checkout, traced_get_socket)
_u(pymongo.pool.Connection.command, _trace_socket_command)
_u(pymongo.pool.Connection.write_command, _trace_socket_write_command)
_u(Server.checkout, traced_get_socket)
else:
_u(pymongo.server.Server.get_socket, traced_get_socket)
_u(pymongo.pool.SocketInfo.command, _trace_socket_command)
_u(pymongo.pool.SocketInfo.write_command, _trace_socket_write_command)
_u(Server.get_socket, traced_get_socket)
_u(Connection.command, _trace_socket_command)
_u(Connection.write_command, _trace_socket_write_command)


@contextlib.contextmanager
Expand Down
Loading
Loading