open-telemetry / opentelemetry-python-contrib

OpenTelemetry instrumentation for Python modules
https://opentelemetry.io
Apache License 2.0
739 stars 612 forks source link

bootstrap.py fails to install `opentelemetry-instrumentation-test==1.0.0b.dev` on version `0.49b0` #2968

Closed nategoethel closed 2 weeks ago

nategoethel commented 2 weeks ago

Describe your environment

OS: Ubuntu Python version: 3.11.6 Package version: 0.49b0

What happened?

The following commands (specifically opentelemetry-bootstrap --action install) fails during docker image build:

# Install OpenTelemetry tracing libraries and set up auto-instrumentation
RUN --mount=type=cache,target=/root/.cache,id=service_pip_cache_${TARGETPLATFORM} \
    python -m pip install opentelemetry-distro opentelemetry-exporter-otlp \
    && opentelemetry-bootstrap --action=install

Here are the logs:

#31 13.95 Successfully installed opentelemetry-instrumentation-requests-0.49b0
#31 14.02 Command '['/opt/venv/bin/python', '-m', 'pip', 'install', '-U', '--upgrade-strategy', 'only-if-needed', 'opentelemetry-instrumentation-test==1.0.0b.dev']' returned non-zero exit status 1.
#31 14.02 Traceback (most recent call last):
#31 14.02   File "/opt/venv/bin/opentelemetry-bootstrap", line 8, in <module>
#31 14.02     sys.exit(run())
#31 14.02              ^^^^^
#31 14.02   File "/opt/venv/lib/python3.11/site-packages/opentelemetry/instrumentation/bootstrap.py", line 186, in run
#31 14.02     cmd(default_instrumentations, libraries)
#31 14.02   File "/opt/venv/lib/python3.11/site-packages/opentelemetry/instrumentation/bootstrap.py", line 138, in _run_install
#31 14.02     for lib in _find_installed_libraries(default_instrumentations, libraries):
#31 14.02   File "/opt/venv/lib/python3.11/site-packages/opentelemetry/instrumentation/bootstrap.py", line 124, in _find_installed_libraries
#31 14.02     if _is_installed(lib["library"]):
#31 14.02        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#31 14.02   File "/opt/venv/lib/python3.11/site-packages/opentelemetry/instrumentation/bootstrap.py", line 108, in _is_installed
#31 14.02     if not req.specifier.filter(dist_version):
#31 14.02            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#31 14.02   File "/opt/venv/lib/python3.11/site-packages/packaging/specifiers.py", line 993, in filter
#31 14.02     parsed_version = _coerce_version(item)
#31 14.02                      ^^^^^^^^^^^^^^^^^^^^^
#31 14.02   File "/opt/venv/lib/python3.11/site-packages/packaging/specifiers.py", line 36, in _coerce_version
#31 14.02     version = Version(version)
#31 14.02               ^^^^^^^^^^^^^^^^
#31 14.02   File "/opt/venv/lib/python3.11/site-packages/packaging/version.py", line 198, in __init__
#31 14.02     raise InvalidVersion(f"Invalid version: '{version}'")
#31 14.02 packaging.version.InvalidVersion: Invalid version: '.'
#31 ERROR: process "/bin/sh -c python -m pip install opentelemetry-distro opentelemetry-exporter-otlp     && opentelemetry-bootstrap --action=install" did not complete successfully: exit code: 1

Steps to Reproduce

I'm not able to reproduce this locally, but it happens regularly in our CI pipelines.

Expected Result

opentelemetry-bootstrap --action install works with the latest release.

Actual Result

Failure

Additional context

No response

Would you like to implement a fix?

None

rayrapetyan commented 2 weeks ago

Although the issue seems to be caused by:

opentelemetry-instrumentation-test==1.0.0b.dev

the actual error originates from the sqlalchemy dependency (if included in your project): https://github.com/open-telemetry/opentelemetry-python-contrib/blob/77613da39651e9406f163249c5cc90e6e226d964/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py#L164; It appears to be the only module missing a version specifier (e.g., >= 3.0). Adding this version specifier resolves the issue on my end. Looks like something has changes in Python packaging module recently as I don't see any changes in bootstrap_gen.py.

@emdneto, please hold off on merging your PR and consider fixing this line first.

xrmx commented 2 weeks ago

@rayrapetyan It's not just sqlalchemy, got the same error and I don't have sqlalchemy on my env.

Also the package is empty so am not sure why we even keep it around.

Lelor commented 2 weeks ago

+1 getting the same error

Lelor commented 2 weeks ago

@emdneto do we have a workaround for this while the fix is not deployed? I could not find a flag to exclude libraries from opentelemetry-bootstrap

nategoethel commented 2 weeks ago

@Lelor downgrading the last release (0.48b0) has generally worked for us.

rayrapetyan commented 2 weeks ago

@rayrapetyan It's not just sqlalchemy, got the same error and I don't have sqlalchemy on my env.

I was wrong saying sqlalchemy should be in the list of dependencies of your project (seems it fails for everyone), but still the "packaging.version.InvalidVersion: Invalid version: '.'" error comes from the sqlalchemy version specifier absence and not the presence of "opentelemetry-instrumentation-test==1.0.0b.dev" (at least on my machine)

lzchen commented 2 weeks ago

@rayrapetyan

We are in the process of resolving both issues separately, one to remove "opentelemetry-instrumentation-test==1.0.0b.dev" as a dependency and the other to add the version constraint to sqlalchemy, both of which will be released together in a patch soon. Ill update this issue once those are resolved.