From 6fd85dd0032a5db04adeff99fdd086c869ceed29 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Mon, 4 Nov 2024 13:35:44 +0100 Subject: [PATCH] opentelemetry-instrumentation-system-metrics: don't report files descriptors on windows --- .../instrumentation/system_metrics/__init__.py | 5 ++++- .../tests/test_system_metrics.py | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py b/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py index 0953e65fb5..4e1ee2a5df 100644 --- a/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py @@ -397,7 +397,10 @@ def _instrument(self, **kwargs): unit="switches", ) - if "process.open_file_descriptor.count" in self._config: + if ( + sys.platform != "win32" + and "process.open_file_descriptor.count" in self._config + ): self._meter.create_observable_up_down_counter( name="process.open_file_descriptor.count", callbacks=[self._get_open_file_descriptors], diff --git a/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py b/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py index bf3a5c6ee2..c34c28ca15 100644 --- a/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py +++ b/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py @@ -14,6 +14,7 @@ # pylint: disable=protected-access +import sys from collections import namedtuple from platform import python_implementation from unittest import mock, skipIf @@ -118,15 +119,16 @@ def test_system_metrics_instrument(self): f"process.runtime.{self.implementation}.thread_count", f"process.runtime.{self.implementation}.context_switches", f"process.runtime.{self.implementation}.cpu.utilization", - "process.open_file_descriptor.count", ] + on_windows = sys.platform == "win32" if self.implementation == "pypy": - self.assertEqual(len(metric_names), 21) + self.assertEqual(len(metric_names), 21 if on_windows else 20) else: - self.assertEqual(len(metric_names), 22) + self.assertEqual(len(metric_names), 22 if on_windows else 21) observer_names.append( f"process.runtime.{self.implementation}.gc_count", + "process.open_file_descriptor.count", ) for observer in metric_names: