-
Notifications
You must be signed in to change notification settings - Fork 440
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
Python autoinstrumentation setting of PYTHONPATH is not compliant with Python's module resolution behavior, breaking Django applications #2302
Comments
@jennydaman I'd like to isolate either the operator or the python autoinstrumentation as the culprit. Is it possible for you to try adding the python auto-instrumentation yourself instead of depending on the operator? |
I’ll try doing a smaller reproduction case with a minimal Django project tomorrow. |
https://github.com/jennydaman/otel_django_2302 @TylerHelmuth please check out the repo above. I've isolated the culprit to be python autoinstrumentation, not the Instrumentation operator. Interestingly, my minimal reproduction case is buggier than my actual application. I can't get both imports and opentelemetry working. |
pinging @open-telemetry/python-maintainers since I don't have permission to transfer the issue. |
thanks for reporting @TylerHelmuth, will ask for this issue to be transferred to us. |
I looked into this issue, found these 2 PRs that seem related: open-telemetry/opentelemetry-python#1583 |
@jennydaman Which are these best practices you mention? |
@ocelotl various sources (of various official-ness) suggest that the best practice is for Python packages to be "pip installed" (or
https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/
In other words, the practice of dropping files in CWD and hoping it'll work is allowed but generally discouraged. |
Component(s)
instrumentation
What happened?
Description
Python's import system is full of implicit behavior. Notably, modules can be imported from the current working directory. The best practice is for applications to be
pip install
-ed so that the import logic is more predictable and reliable. Nevertheless, it is valid (albeit discouraged) for a containerized Python application to work by importing modules from the current working directory.Python imports are dynamic and procedural, and some applications/frameworks such as Django are sensitive to the order of module resolution. Thus, setting
PYTHONPATH
can break valid Python programs which would otherwise work with unsetPYTHONPATH
.Steps to Reproduce
I am trying to run the
chris
chart from https://github.com/FNNDSC/charts. This is a Python application using celery, django, and gunicorn. It works (tested in GitHub Actions) without autoinstrumentation. However, when the annotationinstrumentation.opentelemetry.io/inject-python: "true"
is added to the pod, I get seemingly unrelated error messages about the Django configuration.For debugging, I edited the
command
of my containers tosleep 100000
and then tried running the actual command interactively usingkubectl exec ...
Expected Result
I expect the following commands to do nothing successfully:
Actual Result
All except for (B) work. (B) crashes with a Django-related message
Kubernetes Version
1.27.3
Operator version
0.87.0
Collector version
0.86.0
Environment information
No response
Log output
No response
Additional context
Somewhat related to #1884 (comment), however the container image I am using does not use a custom
PYTHONPATH
. Thechris
application is a fairly standard Django application, its container image is based onregistry.access.redhat.com/ubi9/python-311:1-17.1692772360
and its dependencies are installed withpip
. Nothing magical going on here.I propose two solutions: either
PYTHONPATH
added by InstrumentationThe text was updated successfully, but these errors were encountered: