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

Pymongo 4.9+ doesn't compatible with current ddtrace-py #10714

Open
kimwonj77 opened this issue Sep 19, 2024 · 1 comment
Open

Pymongo 4.9+ doesn't compatible with current ddtrace-py #10714

kimwonj77 opened this issue Sep 19, 2024 · 1 comment
Assignees

Comments

@kimwonj77
Copy link

kimwonj77 commented Sep 19, 2024

Summary of problem

There's no problem with pymongo 4.8.0 but after intialize new project with 4.9.1, got this error :

failed to import ddtrace module 'ddtrace.contrib.pymongo' when patching on import
Traceback (most recent call last):
  File "<redacted>/.venv/lib/python3.11/site-packages/ddtrace/_monkey.py", line 165, in on_import
    imported_module = importlib.import_module(path)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.rye/py/[email protected]/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<redacted>/.venv/lib/python3.11/site-packages/ddtrace/internal/module.py", line 309, in _exec_module
    self.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<redacted>/.venv/lib/python3.11/site-packages/ddtrace/contrib/pymongo/__init__.py", line 46, in <module>
    from . import patch as _  # noqa: F401, I001
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<redacted>/.venv/lib/python3.11/site-packages/ddtrace/internal/module.py", line 309, in _exec_module
    self.loader.exec_module(module)
  File "<redacted>/.venv/lib/python3.11/site-packages/ddtrace/contrib/pymongo/patch.py", line 1, in <module>
    from ..internal.pymongo.patch import *  # noqa: F401,F403
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<redacted>/.venv/lib/python3.11/site-packages/ddtrace/internal/module.py", line 309, in _exec_module
    self.loader.exec_module(module)
  File "<redacted>/.venv/lib/python3.11/site-packages/ddtrace/contrib/internal/pymongo/patch.py", line 39, in <module>
    _VERIFY_VERSION_CLASS = pymongo.pool.SocketInfo if _VERSION < (4, 5) else pymongo.pool.Connection
                                                                              ^^^^^^^^^^^^
AttributeError: partially initialized module 'pymongo' has no attribute 'pool' (most likely due to a circular import)

Which version of dd-trace-py are you using?

2.12.2

Which version of pip are you using?

pip 24.0

Which libraries and their versions are you using?

`pip freeze` pymongo>=4.8.0

How can we reproduce your problem?

patch_all with pymongo 4.9.1

What is the result that you get?

got error. see the summary

What is the result that you expected?

no error.

@mabdinur
Copy link
Contributor

mabdinur commented Sep 19, 2024

Hi @kimwonj77,

Thanks for opening this issue. I was able to reproduce this error with the following steps:

pip install ddtrace==2.11.6 pymongo==4.9.1
python -c "import ddtrace; ddtrace.patch_all(pymongo=True); import pymongo"

In v4.9.0 pymongo modules were significantly refactored. For example:

After these changes applying the ddtrace pymongo integration started to raise an AttributeError. This prevented our pymongo integration from being enabled and logged the error above. I opened a PR to address this issue: #10718.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants