Skip to content

Commit 379ef02

Browse files
committed
Remove sitecustomize path from PYTHONPATH
Fixes #1580 This is necessary to avoid sitecustomize from being run more than once if the command executed byt opentelemetry-instrument also invokes the python interpreter.
1 parent f840c31 commit 379ef02

File tree

1 file changed

+8
-0
lines changed
  • opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation

1 file changed

+8
-0
lines changed

Diff for: opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import sys
1616
from logging import getLogger
1717
from os import environ, path
18+
from os.path import abspath, dirname, pathsep
19+
from re import sub
1820

1921
from pkg_resources import iter_entry_points
2022

@@ -83,6 +85,12 @@ def initialize():
8385
_load_instrumentors()
8486
except Exception: # pylint: disable=broad-except
8587
logger.exception("Failed to auto initialize opentelemetry")
88+
finally:
89+
environ["PYTHONPATH"] = sub(
90+
r"{}{}?".format(dirname(abspath(__file__)), pathsep),
91+
"",
92+
environ["PYTHONPATH"],
93+
)
8694

8795

8896
if (

0 commit comments

Comments
 (0)