diff --git a/src/lumigo_opentelemetry/__init__.py b/src/lumigo_opentelemetry/__init__.py index d7fa421f..1991074b 100644 --- a/src/lumigo_opentelemetry/__init__.py +++ b/src/lumigo_opentelemetry/__init__.py @@ -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" diff --git a/src/test/unit/test_tracer.py b/src/test/unit/test_tracer.py index e28f6849..7cc57b05 100644 --- a/src/test/unit/test_tracer.py +++ b/src/test/unit/test_tracer.py @@ -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], + )