Skip to content

Commit 39f81ce

Browse files
committed
Don't touch PYTHONPATH if not set
1 parent 2dfdff2 commit 39f81ce

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ def run() -> None:
121121
def initialize():
122122
"""Setup auto-instrumentation, called by the sitecustomize module"""
123123
# prevents auto-instrumentation of subprocesses if code execs another python process
124-
environ["PYTHONPATH"] = _python_path_without_directory(
125-
environ.get("PYTHONPATH", ""), dirname(abspath(__file__)), pathsep
126-
)
124+
if "PYTHONPATH" in environ:
125+
environ["PYTHONPATH"] = _python_path_without_directory(
126+
environ["PYTHONPATH"], dirname(abspath(__file__)), pathsep
127+
)
127128

128129
try:
129130
distro = _load_distro()

opentelemetry-instrumentation/tests/auto_instrumentation/test_initialize.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class TestInitialize(TestCase):
3030
@patch("opentelemetry.instrumentation.auto_instrumentation._logger")
3131
def test_handles_pythonpath_not_set(self, logger_mock):
3232
auto_instrumentation.initialize()
33-
self.assertEqual(environ["PYTHONPATH"], "")
33+
self.assertNotIn("PYTHONPATH", environ)
3434
logger_mock.exception.assert_not_called()
3535

3636
@patch.dict("os.environ", {"PYTHONPATH": "."})

0 commit comments

Comments
 (0)