Skip to content

ImportError: cannot import name '_set_http_host' from 'opentelemetry.instrumentation._semconv'  #2099

@cforce

Description

@cforce

Since i switched on app insight opentelemetry dependency incompatibilities fights back. I still don't have an explanation as version
opentelemetry-instrumentation==0.47b0 used in requirements.txt definitely has a method "set_http_host"

ImportError: cannot import name '_set_http_host' from 'opentelemetry.instrumentation._semconv' (/agents/python/opentelemetry/instrumentation/_semconv.py)

opentelemetry-instrumentation==0.47b0

https://github.com/open-telemetry/opentelemetry-python-contrib/blob/07c3324a3bcf80ee716f90b2456f59af08b685fa/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py#L329

The import is used at app.py:35

"from opentelemetry.instrumentation.httpx import (
HTTPXClientInstrumentor,
)

What makes me curios is

ImportError: cannot import name '_set_http_host' from 'opentelemetry.instrumentation._semconv' (/agents/python/opentelemetry/instrumentation/_semconv.py)

It looks like it tries to load the module froma by Azure at runtime injected pypath which is set by an Agent. So this agnet my not use at all the proper version opentelemetry-instrumentation==0.47b0 .

2024-10-30T22:49:46.200141546Z Traceback (most recent call last):
2024-10-30T22:49:46.200149647Z   File "/opt/python/3.11.8/lib/python3.11/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
2024-10-30T22:49:46.200154747Z     worker.init_process()
2024-10-30T22:49:46.200158747Z   File "/tmp/8dcf930cbcef97b/antenv/lib/python3.11/site-packages/uvicorn/workers.py", line 75, in init_process
2024-10-30T22:49:46.200164847Z     super().init_process()
2024-10-30T22:49:46.200168747Z   File "/opt/python/3.11.8/lib/python3.11/site-packages/gunicorn/workers/base.py", line 134, in init_process
2024-10-30T22:49:46.200172747Z     self.load_wsgi()
2024-10-30T22:49:46.200176547Z   File "/opt/python/3.11.8/lib/python3.11/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2024-10-30T22:49:46.200180947Z     self.wsgi = self.app.wsgi()
2024-10-30T22:49:46.200184947Z                 ^^^^^^^^^^^^^^^
2024-10-30T22:49:46.200189047Z   File "/opt/python/3.11.8/lib/python3.11/site-packages/gunicorn/app/base.py", line 67, in wsgi
2024-10-30T22:49:46.200193347Z     self.callable = self.load()
2024-10-30T22:49:46.200197347Z                     ^^^^^^^^^^^
2024-10-30T22:49:46.200201047Z   File "/opt/python/3.11.8/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2024-10-30T22:49:46.200205547Z     return self.load_wsgiapp()
2024-10-30T22:49:46.200210447Z            ^^^^^^^^^^^^^^^^^^^
2024-10-30T22:49:46.200215147Z   File "/opt/python/3.11.8/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2024-10-30T22:49:46.200219647Z     return util.import_app(self.app_uri)
2024-10-30T22:49:46.200224247Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-10-30T22:49:46.200228347Z   File "/opt/python/3.11.8/lib/python3.11/site-packages/gunicorn/util.py", line 371, in import_app
2024-10-30T22:49:46.200232947Z     mod = importlib.import_module(module)
2024-10-30T22:49:46.200237547Z           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-10-30T22:49:46.200242347Z   File "/opt/python/3.11.8/lib/python3.11/importlib/__init__.py", line 126, in import_module
2024-10-30T22:49:46.200247147Z     return _bootstrap._gcd_import(name[level:], package, level)
2024-10-30T22:49:46.200251448Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-10-30T22:49:46.200255648Z   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
2024-10-30T22:49:46.200260048Z   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
2024-10-30T22:49:46.200264048Z   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
2024-10-30T22:49:46.200279448Z   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
2024-10-30T22:49:46.200284248Z   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
2024-10-30T22:49:46.200288748Z   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2024-10-30T22:49:46.200294848Z   File "/tmp/8dcf930cbcef97b/main.py", line 3, in <module>
2024-10-30T22:49:46.200299848Z     from app import create_app
2024-10-30T22:49:46.200304048Z   File "/tmp/8dcf930cbcef97b/app.py", line 35, in <module>
2024-10-30T22:49:46.200308248Z     from opentelemetry.instrumentation.httpx import (
2024-10-30T22:49:46.200312148Z   File "/tmp/8dcf930cbcef97b/antenv/lib/python3.11/site-packages/opentelemetry/instrumentation/httpx/__init__.py", line 199, in <module>
2024-10-30T22:49:46.200316748Z     from opentelemetry.instrumentation._semconv import (
2024-10-30T22:49:46.200321148Z ImportError: cannot import name '_set_http_host' from 'opentelemetry.instrumentation._semconv' (/agents/python/opentelemetry/instrumentation/_semconv.py)

Metadata

Metadata

Assignees

No one assigned

    Labels

    appserviceRelated specifically to deployment to Azure App Service

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions