diff --git a/src/lumigo_opentelemetry/__init__.py b/src/lumigo_opentelemetry/__init__.py index 907c8643..358f0eb2 100644 --- a/src/lumigo_opentelemetry/__init__.py +++ b/src/lumigo_opentelemetry/__init__.py @@ -78,19 +78,26 @@ def auto_load(_: Any) -> None: def init() -> Dict[str, Any]: """Initialize the Lumigo OpenTelemetry distribution.""" - python_version = sys.version_info - # Check if the major version is 3 and the minor version is between 8 and 11 - if python_version.major != 3 or not (8 <= python_version.minor <= 11): - logger.warning( - f"Unsupported Python version {python_version.major}.{python_version.minor}; " - "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" - ) + try: + python_version = sys.version_info + # Check if the major version is 3 and the minor version is between 8 and 11 + if python_version.major != 3 or not (8 <= python_version.minor <= 11): + logger.warning( + f"Unsupported Python version {python_version.major}.{python_version.minor}; " + "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" + ) + return {} + + except AttributeError as e: # Catch any issues with accessing sys.version_info + # Log a warning if there is a failure in verifying the Python version + logger.warning("Failed to verify the Python version due to: %s", str(e)) return {} # Multiple packages are passed to autowrapt in comma-separated form