Skip to content

Remove packaging as a runtime dependency of opentelemetry-instrumentation - #4883

Open
ocelotl wants to merge 2 commits into
open-telemetry:mainfrom
ocelotl:issue_4882_remove_packaging_dependency
Open

Remove packaging as a runtime dependency of opentelemetry-instrumentation#4883
ocelotl wants to merge 2 commits into
open-telemetry:mainfrom
ocelotl:issue_4882_remove_packaging_dependency

Conversation

@ocelotl

@ocelotl ocelotl commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Description

Removes packaging as a runtime dependency of opentelemetry-instrumentation,
replacing its use with a small internal implementation under
opentelemetry.instrumentation._packaging:

  • PEP 440 Version (parsing, normalization, ordering) for the schema-version
    comparison in _semconv.py.
  • PEP 508 Requirement parsing plus PEP 440 specifier containment and marker
    evaluation for the dependency-conflict machinery in dependencies.py and
    bootstrap.py.

packaging is dropped from opentelemetry-instrumentation's dependencies.

Motivation: the auto-instrumentation injector ships instrumentation and its
runtime dependencies onto the target application's PYTHONPATH, so every runtime
dependency (like packaging) is injected into the user's process and risks
version shadowing/conflicts. See the issue for details.

The same removal for the four instrumentations that depend on packaging
(falcon #4884, flask #4885, pika #4886, sqlalchemy #4887) is handled in separate
PRs that reuse the internal implementation introduced here.

Fixes #4882

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • New unit tests for the internal version, specifiers, requirements and markers
    modules (tests/test_packaging_*.py).
  • The internal implementation was validated against packaging across a broad
    corpus of PEP 440 versions and specifiers (parsing, normalization, attributes
    and ordering) with no divergence.
  • Existing test_dependencies.py continues to pass against the internal
    implementation.

Does This PR Require a Core Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@ocelotl
ocelotl force-pushed the issue_4882_remove_packaging_dependency branch from d009c76 to d13f378 Compare July 28, 2026 22:23
@ocelotl ocelotl changed the title Remove packaging as a runtime dependency of the instrumentation packages Remove packaging as a runtime dependency of opentelemetry-instrumentation Jul 28, 2026
@ocelotl
ocelotl force-pushed the issue_4882_remove_packaging_dependency branch 3 times, most recently from 476387a to 6de1be6 Compare July 28, 2026 23:10
@ocelotl
ocelotl marked this pull request as ready for review July 28, 2026 23:14
@ocelotl
ocelotl requested a review from a team as a code owner July 28, 2026 23:14
ocelotl added 2 commits July 28, 2026 18:23
Adds opentelemetry.instrumentation._packaging with PEP 440 Version and PEP 508
Requirement/specifier/marker support, implementing the subset of packaging used
by opentelemetry-instrumentation. Behaviour was validated against packaging
across a large corpus of version/specifier/marker/requirement inputs.
Points _semconv (version comparison) and dependencies.py/bootstrap.py
(requirement parsing) at opentelemetry.instrumentation._packaging, removes
packaging from opentelemetry-instrumentation's runtime dependencies and
refreshes uv.lock.
@ocelotl
ocelotl force-pushed the issue_4882_remove_packaging_dependency branch from 6de1be6 to ebabae2 Compare July 28, 2026 23:23
ocelotl added a commit to dash0hq/opentelemetry-python-distribution that referenced this pull request Aug 5, 2026
…acement

The injector bootstrap script (sitecustomize.py) used packaging.Requirement
and packaging.Version for its dependency-conflict check, making the distro's
own code depend on packaging being importable in the injected process.

Vendor the small PEP 440/508 implementation from
opentelemetry.instrumentation._packaging (open-telemetry/opentelemetry-python-contrib#4883)
as dash0.opentelemetry.injector._packaging and import Requirement/Version from
there instead. The copy is verbatim except for rewritten internal import paths.

TO BE REMOVED: once the same local implementation is available in
opentelemetry-instrumentation (i.e. it ships _packaging in a release this
distribution pins), delete the vendored package and its tests and repoint the
imports in sitecustomize.py and the tests to
opentelemetry.instrumentation._packaging. The note is recorded in the vendored
_packaging/__init__.py and at the sitecustomize.py import site.

sitecustomize.py uses SpecifierSet.contains() rather than the `in` operator,
matching upstream, since the vendored specifiers deliberately do not implement
__contains__.

The two tests that imported packaging (test_sitecustomize.py, test_instrumentations.py)
now import from the vendored module; the vendored upstream tests are included.
The vendored code and its tests are excluded from ruff, as with the other
vendored packages.

The packaging == 26.2 pin in pyproject.toml stays: packaging is still pulled in
transitively via opentelemetry-instrumentation, so check_pinned_dependencies
still requires it declared. It can be removed once that transitive dependency
is gone.

Bump the distro version 0.3.1 -> 0.3.2 (packaged files changed).

Refs #48
mmanciop pushed a commit to dash0hq/opentelemetry-python-distribution that referenced this pull request Aug 6, 2026
…acement (#53)

The injector bootstrap script (sitecustomize.py) used packaging.Requirement
and packaging.Version for its dependency-conflict check, making the distro's
own code depend on packaging being importable in the injected process.

Vendor the small PEP 440/508 implementation from
opentelemetry.instrumentation._packaging (open-telemetry/opentelemetry-python-contrib#4883)
as dash0.opentelemetry.injector._packaging and import Requirement/Version from
there instead. The copy is verbatim except for rewritten internal import paths.

TO BE REMOVED: once the same local implementation is available in
opentelemetry-instrumentation (i.e. it ships _packaging in a release this
distribution pins), delete the vendored package and its tests and repoint the
imports in sitecustomize.py and the tests to
opentelemetry.instrumentation._packaging. The note is recorded in the vendored
_packaging/__init__.py and at the sitecustomize.py import site.

sitecustomize.py uses SpecifierSet.contains() rather than the `in` operator,
matching upstream, since the vendored specifiers deliberately do not implement
__contains__.

The two tests that imported packaging (test_sitecustomize.py, test_instrumentations.py)
now import from the vendored module; the vendored upstream tests are included.
The vendored code and its tests are excluded from ruff, as with the other
vendored packages.

The packaging == 26.2 pin in pyproject.toml stays: packaging is still pulled in
transitively via opentelemetry-instrumentation, so check_pinned_dependencies
still requires it declared. It can be removed once that transitive dependency
is gone.

Bump the distro version 0.3.1 -> 0.3.2 (packaged files changed).

Refs #48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Remove packaging as a runtime dependency of opentelemetry-instrumentation

1 participant