Skip to content

Commit be971fb

Browse files
committed
Move environment variable to proper module
1 parent bf757f2 commit be971fb

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
_load_distro,
2727
_load_instrumentors,
2828
)
29+
from opentelemetry.instrumentation.environment_variables import (
30+
OTEL_PYTHON_AUTO_INSTRUMENTATION_EXPERIMENTAL_GEVENT_PATCH,
31+
)
2932
from opentelemetry.instrumentation.utils import _python_path_without_directory
3033
from opentelemetry.instrumentation.version import __version__
3134
from opentelemetry.util._importlib_metadata import entry_points
@@ -134,14 +137,14 @@ def initialize(*, swallow_exceptions: bool = True) -> None:
134137

135138
# handle optional gevent monkey patching. This is done via environment variables so it may be used from the
136139
# opentelemetry operator
137-
gevent_patch_env_variable_name = (
138-
"OTEL_PYTHON_AUTO_INSTRUMENTATION_EXPERIMENTAL_GEVENT_PATCH"
140+
gevent_patch: str | None = environ.get(
141+
OTEL_PYTHON_AUTO_INSTRUMENTATION_EXPERIMENTAL_GEVENT_PATCH
139142
)
140-
gevent_patch: str | None = environ.get(gevent_patch_env_variable_name)
141143
if gevent_patch is not None:
142144
if gevent_patch != "patch_all":
143145
_logger.error(
144-
"%s values must be `patch_all`", gevent_patch_env_variable_name
146+
"%s value must be `patch_all`",
147+
OTEL_PYTHON_AUTO_INSTRUMENTATION_EXPERIMENTAL_GEVENT_PATCH,
145148
)
146149
else:
147150
try:

opentelemetry-instrumentation/src/opentelemetry/instrumentation/environment_variables.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@
2626
"""
2727
.. envvar:: OTEL_PYTHON_CONFIGURATOR
2828
"""
29+
30+
OTEL_PYTHON_AUTO_INSTRUMENTATION_EXPERIMENTAL_GEVENT_PATCH = (
31+
"OTEL_PYTHON_AUTO_INSTRUMENTATION_EXPERIMENTAL_GEVENT_PATCH"
32+
)
33+
"""
34+
.. envvar:: OTEL_PYTHON_AUTO_INSTRUMENTATION_EXPERIMENTAL_GEVENT_PATCH
35+
"""

opentelemetry-instrumentation/tests/auto_instrumentation/test_initialize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_handles_invalid_gevent_monkeypatch(self, logger_mock):
8484
# pylint:disable=no-self-use
8585
auto_instrumentation.initialize()
8686
logger_mock.error.assert_called_once_with(
87-
"%s values must be `patch_all`",
87+
"%s value must be `patch_all`",
8888
"OTEL_PYTHON_AUTO_INSTRUMENTATION_EXPERIMENTAL_GEVENT_PATCH",
8989
)
9090

0 commit comments

Comments
 (0)