dd-trace-py
dd-trace-py copied to clipboard
pkg_resources is deprecated as an API
Summary of problem
We are seeing deprecation warnings when loading the ddtrace library. This was first reported in #6966 and supposedly fixed in v2.2.0 with #6985, but we are still seeing the warning.
Which version of dd-trace-py are you using?
This happens with ddtrace v2.3.1.
Which version of pip are you using?
Python 3.12.1 and pip 23.3.1.
Which libraries and their versions are you using?
Not relevant.
How can we reproduce your problem?
Import and use the ddtrace library.
The line in question: https://github.com/DataDog/dd-trace-py/blob/v2.3.1/ddtrace/internal/module.py#L211C38-L211C38
The line is present in 2.3.2 and main (line 225).
What is the result that you get?
~/.pyenv/versions/3.12.1/lib/python3.12/site-packages/ddtrace/internal/module.py:211
~/.pyenv/versions/3.12.1/lib/python3.12/site-packages/ddtrace/internal/module.py:211: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
self.loader.exec_module(module)
What is the result that you expected?
No warning.
Thanks for the issue report, @sodul. I'm surprised that this is still happening - probably the result of a transitive dependency on pkg_resources
. We'll take a look!
@emmettbutler This is likely coming from the vendored wrapped dependency: https://github.com/DataDog/dd-trace-py/blob/main/ddtrace/vendor/wrapt/importer.py#L114.
I am hesitant to directly modify files vendored by ddtrace since this can lead to unknown side effects. However we can try to make an upstream contribution to wrapt
to replace pkg_resources with importlib: https://github.com/GrahamDumpleton/wrapt/blob/1.16.0/src/wrapt/importer.py#L94
I did not realize that dd-trace is vendoring additional python packages. It does not look like the vendored versions are tracked explicitly but the wrapt version in the dd-trace repo is definitely different from the latest main of wrapt (1.16.0): https://github.com/GrahamDumpleton/wrapt/blob/1.16.0/src/wrapt/importer.py
The fix might simply be to upgrade to wrapt 1.16.0.
I also suggest that you keep track of the upstream versions of the vendored packages explicitly in the source tree so that such bugs and fixes can be easier to track.
Hi @mabdinur ! I was looking at my warnings today, and this came up again. Did you propose the change up to wrapt yet?
Hello! We are seeing with with ddtrace = 2.9.2
and python = 3.12.4
as well.
I am also seeing this warning with ddtrace==2.10.6
and python==3.12.5
../../.pyenv/versions/3.12.5/envs/myproject/lib/python3.12/site-packages/ddtrace/internal/module.py:250
/.pyenv/versions/3.12.5/envs/myproject/lib/python3.12/site-packages/ddtrace/internal/module.py:250: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
self.loader.exec_module(module)
../../.pyenv/versions/3.12.5/envs/myproject/lib/python3.12/site-packages/pkg_resources/__init__.py:3144
/.pyenv/versions/3.12.5/envs/myproject/lib/python3.12/site-packages/pkg_resources/__init__.py:3144: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
declare_namespace(pkg)
edit: this warning appeared when I was running pytest
(using ddtrace for test visibility)