| 
14 | 14 | 
 
  | 
15 | 15 | # pylint: disable=protected-access,too-many-lines  | 
16 | 16 | 
 
  | 
 | 17 | +import importlib.util  | 
17 | 18 | import sys  | 
18 | 19 | from collections import namedtuple  | 
19 | 20 | from platform import python_implementation  | 
@@ -1091,3 +1092,37 @@ def test_that_correct_config_is_read(self):  | 
1091 | 1092 |             instrumentor.instrument(meter_provider=meter_provider)  | 
1092 | 1093 |             meter_provider.force_flush()  | 
1093 | 1094 |             instrumentor.uninstrument()  | 
 | 1095 | + | 
 | 1096 | +    def test_linux_missing_vmstat_removes_swap_metrics(self):  | 
 | 1097 | +        with (  | 
 | 1098 | +            mock.patch(  | 
 | 1099 | +                target="psutil.LINUX",  | 
 | 1100 | +                new=True,  | 
 | 1101 | +            ),  | 
 | 1102 | +            mock.patch(  | 
 | 1103 | +                target="psutil.PROCFS_PATH",  | 
 | 1104 | +                new="/bogus/path/to/procfs",  | 
 | 1105 | +                create=True,  | 
 | 1106 | +            ),  | 
 | 1107 | +        ):  | 
 | 1108 | +            # Import the module into an isolated, temporary module object under the patched context  | 
 | 1109 | +            spec = importlib.util.find_spec(  | 
 | 1110 | +                "opentelemetry.instrumentation.system_metrics"  | 
 | 1111 | +            )  | 
 | 1112 | +            assert (  | 
 | 1113 | +                spec and spec.origin  | 
 | 1114 | +            ), "Could not find system_metrics module spec"  | 
 | 1115 | + | 
 | 1116 | +            tmp_spec = importlib.util.spec_from_file_location(  | 
 | 1117 | +                name="tmp_system_metrics_for_test",  | 
 | 1118 | +                location=spec.origin,  | 
 | 1119 | +            )  | 
 | 1120 | +            module = importlib.util.module_from_spec(tmp_spec)  | 
 | 1121 | + | 
 | 1122 | +            # Ensure relative imports inside the module resolve correctly  | 
 | 1123 | +            module.__package__ = "opentelemetry.instrumentation.system_metrics"  | 
 | 1124 | +            tmp_spec.loader.exec_module(module)  | 
 | 1125 | + | 
 | 1126 | +            config = getattr(module, "_DEFAULT_CONFIG")  | 
 | 1127 | +            assert "system.swap.usage" not in config  | 
 | 1128 | +            assert "system.swap.utilization" not in config  | 
0 commit comments