open-telemetry / open-telemetry/opentelemetry-python-contrib

pkg_resources deprecation

Open
#4,191 7 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

Describe your environment

Python version: python:3.12-slim
OS: Docker
Package version: latest

What happened?

Hi, today I was building my docker image for python 3.12 slim and while trying to launch the container for gunicorn with uvicorn workers I got this error.

I investigated a bit and it seems setuptools deprecated pkg_resources in its latest versions. I had to force install setuptools<80 to recover this library and everything is working. I am unsure if the issue comes from opentelemetry, because I could not find the dependency anywhere, but I thought raising the issue here could help.

Steps to Reproduce

I launched my fastapi application inside docker with:
gunicorn -w 2 -k uvicorn.workers.UvicornWorker app.main:app --bind 0.0.0.0:8000 --timeout 600 --log-level info

Expected Result

Server should be running

Actual Result

2026-02-11T13:40:05.9640308Z [2026-02-11 13:40:05 +0000] [8] [INFO] Worker exiting (pid: 8)
2026-02-11T13:40:06.0435788Z [2026-02-11 13:40:06 +0000] [9] [ERROR] Exception in worker process
2026-02-11T13:40:06.0436132Z Traceback (most recent call last):
2026-02-11T13:40:06.0436173Z File "/root/.local/lib/python3.12/site-packages/gunicorn/arbiter.py", line 684, in spawn_worker
2026-02-11T13:40:06.0436204Z worker.init_process()
2026-02-11T13:40:06.0436236Z File "/root/.local/lib/python3.12/site-packages/gunicorn/workers/base.py", line 136, in init_process
2026-02-11T13:40:06.0436262Z self.load_wsgi()
2026-02-11T13:40:06.0436295Z File "/root/.local/lib/python3.12/site-packages/gunicorn/workers/base.py", line 148, in load_wsgi
2026-02-11T13:40:06.0436324Z self.wsgi = self.app.wsgi()
2026-02-11T13:40:06.0436352Z ^^^^^^^^^^^^^^^
2026-02-11T13:40:06.0436383Z File "/root/.local/lib/python3.12/site-packages/gunicorn/app/base.py", line 66, in wsgi
2026-02-11T13:40:06.0436481Z self.callable = self.load()
2026-02-11T13:40:06.0436514Z ^^^^^^^^^^^
2026-02-11T13:40:06.0436548Z File "/root/.local/lib/python3.12/site-packages/gunicorn/app/wsgiapp.py", line 57, in load
2026-02-11T13:40:06.0436576Z return self.load_wsgiapp()
2026-02-11T13:40:06.0436603Z ^^^^^^^^^^^^^^^^^^^
2026-02-11T13:40:06.0436633Z File "/root/.local/lib/python3.12/site-packages/gunicorn/app/wsgiapp.py", line 47, in load_wsgiapp
2026-02-11T13:40:06.0436662Z return util.import_app(self.app_uri)
2026-02-11T13:40:06.043669Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2026-02-11T13:40:06.0436718Z File "/root/.local/lib/python3.12/site-packages/gunicorn/util.py", line 377, in import_app
2026-02-11T13:40:06.0436747Z mod = importlib.import_module(module)
2026-02-11T13:40:06.0436776Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2026-02-11T13:40:06.0436818Z File "/usr/local/lib/python3.12/importlib/init.py", line 90, in import_module
2026-02-11T13:40:06.0436849Z return _bootstrap._gcd_import(name[level:], package, level)
2026-02-11T13:40:06.043688Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2026-02-11T13:40:06.0436911Z File "", line 1387, in _gcd_import
2026-02-11T13:40:06.0436938Z File "", line 1360, in _find_and_load
2026-02-11T13:40:06.0436968Z File "", line 1331, in _find_and_load_unlocked
2026-02-11T13:40:06.0436996Z File "", line 935, in _load_unlocked
2026-02-11T13:40:06.0437027Z File "", line 999, in exec_module
2026-02-11T13:40:06.0437055Z File "", line 488, in _call_with_frames_removed
2026-02-11T13:40:06.0437081Z File "/app/app/main.py", line 2, in
2026-02-11T13:40:06.0437124Z from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
2026-02-11T13:40:06.0437157Z File "/root/.local/lib/python3.12/site-packages/opentelemetry/instrumentation/fastapi/init.py", line 184, in
2026-02-11T13:40:06.0437188Z from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
2026-02-11T13:40:06.0437218Z File "/root/.local/lib/python3.12/site-packages/opentelemetry/instrumentation/instrumentor.py", line 27, in
2026-02-11T13:40:06.0437246Z from opentelemetry.instrumentation.dependencies import (
2026-02-11T13:40:06.0437278Z File "/root/.local/lib/python3.12/site-packages/opentelemetry/instrumentation/dependencies.py", line 4, in
2026-02-11T13:40:06.0437306Z from pkg_resources import (
2026-02-11T13:40:06.0437333Z ModuleNotFoundError: No module named 'pkg_resources'
2026-02-11T13:40:06.0437595Z No module named 'pkg_resources'

Additional context

No response

Would you like to implement a fix?

None

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the import in opentelemetry/instrumentation/dependencies.py shown in the traceback and inspect the package metadata for the dependency that provides pkg_resources. Reproduce the failure in a Python 3.12 slim Docker image with current setuptools, then verify that the FastAPI instrumentation imports and the reported gunicorn command starts without requiring a setuptools pin.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, fastapi, python
Domain
api, backend, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.