You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
package_version() parses every installed package's metadata, slowing sentry_sdk.init() #8190
Flask deprecated __version__ and #2316 suggested importlib.metadata.version. #2338 fixed the deprecation using _get_installed_modules() instead. #6769 / #6865 addressed the same scan for MCP when mcp isn't installed.
Suggested fix
Have package_version call importlib.metadata.version(package), keeping the existing path for Python < 3.8 and returning None on PackageNotFoundError. ModulesIntegration would still build the full list on the first error event. Happy to open a PR if this approach works for you.
Expected Result
Checking Flask's minimum version costs about as much as looking up one package.
Actual Result
FlaskIntegration.setup_once calls package_version("flask"), which parses the metadata of every installed package just to read one version. importlib.metadata.version("flask"), as suggested in #2316, reads only Flask's.
With ~250 packages: package_version("flask") takes 106 ms, and importlib.metadata.version("flask") takes 5 ms (-95%).
Hi, I'd like to pick this up. Plan: make package_version() in sentry_sdk/utils.py look up the single distribution via importlib.metadata.version() (top-level guarded import, PackageNotFoundError -> None), keeping the existing _get_installed_modules() scan only as the fallback when importlib.metadata is unavailable (Python < 3.8). Tests: extend tests/test_utils.py with an installed-package case and a regression test asserting the full installed-modules scan is not invoked. Will validate with tox (py3.12-common), ruff, and mypy as per the repo guidelines.
Activity
linear-code commentedon Nov 4, 2026
PY-3058
Shellghostt commentedon Nov 8, 2026
Hi, I'd like to pick this up. Plan: make
package_version()insentry_sdk/utils.pylook up the single distribution viaimportlib.metadata.version()(top-level guarded import,PackageNotFoundError->None), keeping the existing_get_installed_modules()scan only as the fallback whenimportlib.metadatais unavailable (Python < 3.8). Tests: extendtests/test_utils.pywith an installed-package case and a regression test asserting the full installed-modules scan is not invoked. Will validate with tox (py3.12-common), ruff, and mypy as per the repo guidelines.