opentelemetry-python-contrib icon indicating copy to clipboard operation
opentelemetry-python-contrib copied to clipboard

fix(auto-instrumentation): Python path no longer required

Open lperdereau opened this issue 2 years ago • 6 comments
trafficstars

Description

When we implemented the gunicorn.py configuration with a post fork, we wanted to use OTEL auto-instrumentation easily. But a bug appeared when using sitecustomize.

Here is an example of a gunicorn post fork to load auto-instrumentation.

def post_fork(server, worker):
    from opentelemetry.instrumentation.auto_instrumentation import sitecustomize

if we run gunicorn like this

gunicorn my-app.wsgi -c gunicorn.py

An error appear :

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/gunicorn/arbiter.py", line 608, in spawn_worker
    self.cfg.post_fork(self, worker)
  File "gunicorn.py", line 15, in post_fork
    from opentelemetry.instrumentation.auto_instrumentation import sitecustomize
  File "/usr/local/lib/python3.9/site-packages/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py", line 44, in <module>
    initialize()
  File "/usr/local/lib/python3.9/site-packages/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py", line 32, in initialize
    environ["PYTHONPATH"], dirname(abspath(__file__)), pathsep
  File "/usr/local/lib/python3.9/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'PYTHONPATH'

PYTHONPATH should not be required to use this auto-instrument feature.

lperdereau avatar Sep 22 '23 15:09 lperdereau