Skip to content

Commit

Permalink
opentelemetry-instrumentation-system-metrics: don't report files desc…
Browse files Browse the repository at this point in the history
…riptors on windows
  • Loading branch information
xrmx committed Nov 4, 2024
1 parent 07c3324 commit 76c8452
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2940](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2940))
- `opentelemetry-instrumentation-dbapi` sqlcommenter key values created from PostgreSQL, MySQL systems
([#2897](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2897))
- `opentelemetry-instrumentation-system-metrics`: don't report open file descriptors on Windows
([#2946](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2946))

### Breaking changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# pylint: disable=protected-access

import sys
from collections import namedtuple
from platform import python_implementation
from unittest import mock, skipIf
Expand Down Expand Up @@ -118,21 +119,30 @@ 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), 20 if on_windows else 21)
else:
self.assertEqual(len(metric_names), 22)
self.assertEqual(len(metric_names), 21 if on_windows else 22)
observer_names.append(
f"process.runtime.{self.implementation}.gc_count",
)
if not on_windows:
observer_names.append(
"process.open_file_descriptor.count",
)

for observer in metric_names:
self.assertIn(observer, observer_names)
observer_names.remove(observer)

if on_windows:
self.assertNotIn(
"process.open_file_descriptor.count", observer_names
)

def test_runtime_metrics_instrument(self):
runtime_config = {
"process.runtime.memory": ["rss", "vms"],
Expand Down

0 comments on commit 76c8452

Please sign in to comment.