Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `opentelemetry-instrumentation-httpx`: instrument_client is a static method again
([#3003](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3003))
- `opentelemetry-instrumentation-system_metrics`: fix callbacks reading wrong config
([#3025](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3025))

### Breaking changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def _get_system_network_packets(
"""Observer callback for network packets"""

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

for device, counters in psutil.net_io_counters(pernic=True).items():
for metric in self._config["system.network.dropped.packets"]:
for metric in self._config["system.network.io"]:
recv_sent = {"receive": "recv", "transmit": "sent"}[metric]
if hasattr(counters, f"bytes_{recv_sent}"):
self._system_network_io_labels["device"] = device
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from unittest import mock, skipIf

from opentelemetry.instrumentation.system_metrics import (
_DEFAULT_CONFIG,
SystemMetricsInstrumentor,
)
from opentelemetry.sdk.metrics import MeterProvider
Expand Down Expand Up @@ -865,3 +866,14 @@ def test_open_file_descriptor_count(self, mock_process_num_fds):
expected,
)
mock_process_num_fds.assert_called()


class TestConfigSystemMetrics(TestBase):
# pylint:disable=no-self-use
def test_that_correct_config_is_read(self):
for key, value in _DEFAULT_CONFIG.items():
meter_provider = MeterProvider([InMemoryMetricReader()])
instrumentor = SystemMetricsInstrumentor(config={key: value})
instrumentor.instrument(meter_provider=meter_provider)
meter_provider.force_flush()
instrumentor.uninstrument()