Skip to content

Commit

Permalink
python 3.7 runtime check
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Orlovsky committed Sep 2, 2024
1 parent 03154a6 commit a8d59d0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lumigo_opentelemetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ def auto_load(_: Any) -> None:


def init() -> Dict[str, Any]:
"""Initialize the Lumigo OpenTelemetry distribution."""
python_version = sys.version_info
if not (python_version >= (3, 8) and python_version <= (3, 11)):
logger.warning(
f"Unsupported Python version {python_version[0]}.{python_version[1]}; "
"only Python 3.8 to 3.11 are supported."
)
return {}

if str(os.environ.get("LUMIGO_SWITCH_OFF", False)).lower() == "true":
logger.info(
"Lumigo OpenTelemetry distribution disabled via the 'LUMIGO_SWITCH_OFF' environment variable"
Expand Down
28 changes: 28 additions & 0 deletions src/test/unit/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,31 @@ def _test_dependency_report_called(self):
assert resource_attributes and resource_attributes["lumigo.distro.version"]
assert "process.environ" not in resource_attributes.keys()
assert dependencies


class TestPythonVersionCheck(TestCase):
@patch("sys.version_info", (3, 7)) # Set Python version to 3.7
def test_python_version_too_old(self):
with self.assertLogs("lumigo-opentelemetry", level="WARNING") as cm:
result = init()
self.assertEqual(result, {})
self.assertIn(
"Unsupported Python version 3.7; only Python 3.8 to 3.11 are supported.",
cm.output[0],
)

@patch("sys.version_info", (3, 8)) # Set Python version to 3.8
def test_python_version_supported(self):
with self.assertLogs("lumigo-opentelemetry", level="WARNING"):
result = init()
self.assertIsInstance(result, dict)

@patch("sys.version_info", (3, 12)) # Set Python version to 3.12
def test_python_version_too_new(self):
with self.assertLogs("lumigo-opentelemetry", level="WARNING") as cm:
result = init()
self.assertEqual(result, {})
self.assertIn(
"Unsupported Python version 3.12; only Python 3.8 to 3.11 are supported.",
cm.output[0],
)

0 comments on commit a8d59d0

Please sign in to comment.