From 1ad9d9030880d260df3b52c2e2c334b07f1bde4a Mon Sep 17 00:00:00 2001 From: Mrugesh Master Date: Wed, 21 Aug 2024 15:24:46 -0700 Subject: [PATCH] Divided proc_cpu_percent by 100 to get value between 0 and 1 (#2812) --- CHANGELOG.md | 2 ++ .../opentelemetry/instrumentation/system_metrics/__init__.py | 2 +- .../tests/test_system_metrics.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c31e01235..5abca8227a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Fixed +- `opentelemetry-instrumentation-system-metrics` fix `process.runtime.cpu.utilization` values to be shown in range of 0 to 1 + ([2812](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2812)) - `opentelemetry-instrumentation-fastapi` fix `fastapi` auto-instrumentation by removing `fastapi-slim` support, `fastapi-slim` itself is discontinued from maintainers ([2783](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2783)) - `opentelemetry-instrumentation-aws-lambda` Avoid exception when a handler is not present. 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 b7ffb25431..1b9a36c4cb 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 @@ -729,7 +729,7 @@ def _get_runtime_cpu_utilization( """Observer callback for runtime CPU utilization""" proc_cpu_percent = self._proc.cpu_percent() yield Observation( - proc_cpu_percent, + proc_cpu_percent / 100, self._runtime_cpu_utilization_labels.copy(), ) 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 1d6f08892e..bf3a5c6ee2 100644 --- a/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py +++ b/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py @@ -839,7 +839,7 @@ def test_runtime_thread_num(self, mock_process_thread_num): def test_runtime_cpu_percent(self, mock_process_cpu_percent): mock_process_cpu_percent.configure_mock(**{"return_value": 42}) - expected = [_SystemMetricsResult({}, 42)] + expected = [_SystemMetricsResult({}, 0.42)] self._test_metrics( f"process.runtime.{self.implementation}.cpu.utilization", expected )