Skip to content

Commit 1023cc5

Browse files
committed
opentelemetry-instrumentation-system-metrics: fix typo in metrics configs
With default config it behaves correctly, with custom config changing dropped packets affected two other measures.
1 parent a29ad8a commit 1023cc5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ def _get_system_network_packets(
595595
"""Observer callback for network packets"""
596596

597597
for device, counters in psutil.net_io_counters(pernic=True).items():
598-
for metric in self._config["system.network.dropped.packets"]:
598+
for metric in self._config["system.network.packets"]:
599599
recv_sent = {"receive": "recv", "transmit": "sent"}[metric]
600600
if hasattr(counters, f"packets_{recv_sent}"):
601601
self._system_network_packets_labels["device"] = device
@@ -626,7 +626,7 @@ def _get_system_network_io(
626626
"""Observer callback for network IO"""
627627

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

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

Lines changed: 11 additions & 0 deletions
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,13 @@ 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+
def test_that_correct_config_is_read(self):
873+
for k, v in _DEFAULT_CONFIG.items():
874+
meter_provider = MeterProvider([InMemoryMetricReader()])
875+
instrumentor = SystemMetricsInstrumentor(config={k: v})
876+
instrumentor.instrument(meter_provider=meter_provider)
877+
meter_provider.force_flush()
878+
instrumentor.uninstrument()

0 commit comments

Comments
 (0)