Skip to content

Commit d9e1448

Browse files
authored
opentelemetry-instrumentation-system-metrics: fix typo in metrics configs (#3025)
1 parent 116f98d commit d9e1448

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030

3131
- `opentelemetry-instrumentation-httpx`: instrument_client is a static method again
3232
([#3003](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3003))
33+
- `opentelemetry-instrumentation-system_metrics`: fix callbacks reading wrong config
34+
([#3025](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3025))
3335
- `opentelemetry-instrumentation-httpx`: Check if mount transport is none before wrap it
3436
([#3022](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3022))
3537

instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"process.runtime.thread_count": None,
4141
"process.runtime.cpu.utilization": None,
4242
"process.runtime.context_switches": ["involuntary", "voluntary"],
43+
"process.open_file_descriptor.count": None,
4344
}
4445
4546
Usage
@@ -595,7 +596,7 @@ def _get_system_network_packets(
595596
"""Observer callback for network packets"""
596597

597598
for device, counters in psutil.net_io_counters(pernic=True).items():
598-
for metric in self._config["system.network.dropped.packets"]:
599+
for metric in self._config["system.network.packets"]:
599600
recv_sent = {"receive": "recv", "transmit": "sent"}[metric]
600601
if hasattr(counters, f"packets_{recv_sent}"):
601602
self._system_network_packets_labels["device"] = device
@@ -626,7 +627,7 @@ def _get_system_network_io(
626627
"""Observer callback for network IO"""
627628

628629
for device, counters in psutil.net_io_counters(pernic=True).items():
629-
for metric in self._config["system.network.dropped.packets"]:
630+
for metric in self._config["system.network.io"]:
630631
recv_sent = {"receive": "recv", "transmit": "sent"}[metric]
631632
if hasattr(counters, f"bytes_{recv_sent}"):
632633
self._system_network_io_labels["device"] = device

instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from unittest import mock, skipIf
2121

2222
from opentelemetry.instrumentation.system_metrics import (
23+
_DEFAULT_CONFIG,
2324
SystemMetricsInstrumentor,
2425
)
2526
from opentelemetry.sdk.metrics import MeterProvider
@@ -865,3 +866,14 @@ def test_open_file_descriptor_count(self, mock_process_num_fds):
865866
expected,
866867
)
867868
mock_process_num_fds.assert_called()
869+
870+
871+
class TestConfigSystemMetrics(TestBase):
872+
# pylint:disable=no-self-use
873+
def test_that_correct_config_is_read(self):
874+
for key, value in _DEFAULT_CONFIG.items():
875+
meter_provider = MeterProvider([InMemoryMetricReader()])
876+
instrumentor = SystemMetricsInstrumentor(config={key: value})
877+
instrumentor.instrument(meter_provider=meter_provider)
878+
meter_provider.force_flush()
879+
instrumentor.uninstrument()

0 commit comments

Comments
 (0)