Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cforce opened this issue Oct 30, 2024 · 5 comments

Comments

@cforce
Copy link
Contributor

cforce commented Oct 30, 2024

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)
@cforce
Copy link
Contributor Author

cforce commented Oct 30, 2024

I disabled AppInsighs and restarted the server and now it works again.

@pamelafox
Copy link
Collaborator

I saw that as well, and I've reported it to the App Service team. That's why I have not yet merged #2083
This is only with the optional variable, right? Not with the default deployment?

@cforce
Copy link
Contributor Author

cforce commented Nov 1, 2024

I have manually activated in Portal, which is the same result as if I would use.enabled in bicep I assume

@pamelafox
Copy link
Collaborator

Okay, thanks for clarifying, I've reached out again to the App Service team.

@jeremydvoss
Copy link

Yes, disabling autoinstrumentation in the portal is the correct response. It is causing a dependency conflict with the Manual Instrumentation built into this app.

This AI demo includes "azure-monitor-opentelemetry==1.6.1" and enables "Manual instrumentation" with this distro here so long as you set the APPLICATIONINSIGHTS_CONNECTION_STRING. You should only use Manual Instrumentation or Autoinstrumentation, but not both. See this note in our documentation:
Only use autoinstrumentation on App Service if you aren't using manual instrumentation of OpenTelemetry in your code...

Since this test app already uses manual instrumentation, I recommend that anyone who has this issue disable autoinstrumentation. You can do this in the "Application Insights" blade of App Service (or, if you enabled this feature in an ARM template, make sure ApplicationInsightsAgent_EXTENSION_VERSION is set to "disabled").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
@pamelafox @cforce @jeremydvoss and others