-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix import when trace is missing from opentelemetry #2694
Conversation
💚 CLA has been signed |
A documentation preview will be available soon. Request a new doc build by commenting
If your PR continues to fail for an unknown reason, the doc build pipeline may be broken. Elastic employees can check the pipeline status here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While is usually correct to catch
ModuleNotFoundError
, in case of opentelemetry this is a bit different since the actual "opentelemetry" package doesn't exist at all (we got opentelemetry-api and opentelemetry-sdk) and in that case Python (3.11 in my case) throws a more generic ImportError
Actually, the distribution packages opentelemetry-api and opentelemetry-sdk can be accessed with the import package opentelemetry. See https://packaging.python.org/en/latest/discussions/distribution-package-vs-import-package/ to understand the difference. And indeed, if I run pip install opentelemetry-api
, then I can run from opentelemetry import trace
without error.
Most of our CI runs without opentelemetry-api
installed, from Python 3.8 to 3.13. so catching ModuleNotFoundError
is generally correct. What seems to happen is that you have an opentelemetry
import package that does not define trace
somehow. This is possible if you run pip install opentelemetry-sdk
(which will also install opentelemetry-api
) and then manually run pip uninstall opentelemetry-api
. At this point, the import package opentelemetry
still exists (and allows access to opentelemtry.sdk
) but opentelemetry.trace
no longer exists. I don't think the OpenTelemetry SDK can be used without the API, but this should not break the Elasticsearch client, so the pull request looks good to me. Thank you!
buildkite test this please |
(cherry picked from commit de6ed82)
(cherry picked from commit de6ed82)
Thank you for your contribution, it is now released as part of 8.16.0: https://github.com/elastic/elasticsearch-py/releases/tag/v8.16.0 |
otel dependency is optional but if I try to use latest elastic client it fails to bootstrap due to
Fix
While is usually correct to catch
ModuleNotFoundError
, in case of opentelemetry this is a bit different since the actual "opentelemetry" package doesn't exist at all (we got opentelemetry-api and opentelemetry-sdk) and in that case Python (3.11 in my case) throws a more generic ImportError