From f4250c76609eb26f48a0c1b06b471a7700d07c9f Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Thu, 30 Mar 2023 10:38:14 -0400 Subject: [PATCH 1/6] Update runtime metric names to include process --- .../system_metrics/__init__.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) 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 413c61ba8f..45ae75e058 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 @@ -34,8 +34,8 @@ "system.network.io": ["transmit", "receive"], "system.network.connections": ["family", "type"], "system.thread_count": None - "runtime.memory": ["rss", "vms"], - "runtime.cpu.time": ["user", "system"], + "process.runtime.memory": ["rss", "vms"], + "process.runtime.cpu.time": ["user", "system"], } Usage @@ -61,8 +61,8 @@ "system.memory.usage": ["used", "free", "cached"], "system.cpu.time": ["idle", "user", "system", "irq"], "system.network.io": ["transmit", "receive"], - "runtime.memory": ["rss", "vms"], - "runtime.cpu.time": ["user", "system"], + "process.runtime.memory": ["rss", "vms"], + "process.runtime.cpu.time": ["user", "system"], } SystemMetricsInstrumentor(config=configuration).instrument() @@ -102,9 +102,9 @@ "system.network.io": ["transmit", "receive"], "system.network.connections": ["family", "type"], "system.thread_count": None, - "runtime.memory": ["rss", "vms"], - "runtime.cpu.time": ["user", "system"], - "runtime.gc_count": None, + "process.runtime.memory": ["rss", "vms"], + "process.runtime.cpu.time": ["user", "system"], + "process.runtime.gc_count": None, } @@ -323,25 +323,25 @@ def _instrument(self, **kwargs): description="System active threads count", ) - if "runtime.memory" in self._config: + if "process.runtime.memory" in self._config: self._meter.create_observable_counter( - name=f"runtime.{self._python_implementation}.memory", + name=f"process.runtime.{self._python_implementation}.memory", callbacks=[self._get_runtime_memory], description=f"Runtime {self._python_implementation} memory", unit="bytes", ) - if "runtime.cpu.time" in self._config: + if "process.runtime.cpu.time" in self._config: self._meter.create_observable_counter( - name=f"runtime.{self._python_implementation}.cpu_time", + name=f"process.runtime.{self._python_implementation}.cpu_time", callbacks=[self._get_runtime_cpu_time], description=f"Runtime {self._python_implementation} CPU time", unit="seconds", ) - if "runtime.gc_count" in self._config: + if "process.runtime.gc_count" in self._config: self._meter.create_observable_counter( - name=f"runtime.{self._python_implementation}.gc_count", + name=f"process.runtime.{self._python_implementation}.gc_count", callbacks=[self._get_runtime_gc_count], description=f"Runtime {self._python_implementation} GC count", unit="bytes", @@ -618,7 +618,7 @@ def _get_runtime_memory( ) -> Iterable[Observation]: """Observer callback for runtime memory""" proc_memory = self._proc.memory_info() - for metric in self._config["runtime.memory"]: + for metric in self._config["process.runtime.memory"]: if hasattr(proc_memory, metric): self._runtime_memory_labels["type"] = metric yield Observation( @@ -631,7 +631,7 @@ def _get_runtime_cpu_time( ) -> Iterable[Observation]: """Observer callback for runtime CPU time""" proc_cpu = self._proc.cpu_times() - for metric in self._config["runtime.cpu.time"]: + for metric in self._config["process.runtime.cpu.time"]: if hasattr(proc_cpu, metric): self._runtime_cpu_time_labels["type"] = metric yield Observation( From a27535356b7a76ba6534e8503fd773c2b0a00e54 Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Thu, 30 Mar 2023 10:39:18 -0400 Subject: [PATCH 2/6] Change runtime memory to gauge --- .../opentelemetry/instrumentation/system_metrics/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 45ae75e058..83fd25112b 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 @@ -324,7 +324,7 @@ def _instrument(self, **kwargs): ) if "process.runtime.memory" in self._config: - self._meter.create_observable_counter( + self._meter.create_observable_gauge( name=f"process.runtime.{self._python_implementation}.memory", callbacks=[self._get_runtime_memory], description=f"Runtime {self._python_implementation} memory", From 455e52fabaac6ca6e3c3d620a9c8828d6ab2f253 Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Thu, 30 Mar 2023 10:42:48 -0400 Subject: [PATCH 3/6] Change to updowncounter --- .../opentelemetry/instrumentation/system_metrics/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 83fd25112b..b7bd38907e 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 @@ -324,7 +324,7 @@ def _instrument(self, **kwargs): ) if "process.runtime.memory" in self._config: - self._meter.create_observable_gauge( + self._meter.create_observable_up_down_counter( name=f"process.runtime.{self._python_implementation}.memory", callbacks=[self._get_runtime_memory], description=f"Runtime {self._python_implementation} memory", From 88e2a5c8c8d4e89dad408a0027cea93b7fda4698 Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Thu, 30 Mar 2023 11:19:37 -0400 Subject: [PATCH 4/6] Update test and changelog --- CHANGELOG.md | 1 + .../tests/test_system_metrics.py | 24 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce84cd8a67..995fe18b21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-instrumentation-requests` Replace `name_callback` and `span_callback` with standard `response_hook` and `request_hook` callbacks ([#670](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/670)) +- `opentelemetry-instrumentation-system-metrics` Add `process.` prefix to `runtime.memory`, `runtime.cpu.time`, and `runtime.gc_count`. Change `runtime.memory` from count to UpDownCounter. ([#1735](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1735)) ## Version 1.16.0/0.37b0 (2023-02-17) 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 763f629ed5..de12f6d73a 100644 --- a/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py +++ b/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py @@ -114,9 +114,9 @@ def test_system_metrics_instrument(self): "system.network.io", "system.network.connections", "system.thread_count", - f"runtime.{self.implementation}.memory", - f"runtime.{self.implementation}.cpu_time", - f"runtime.{self.implementation}.gc_count", + f"process.runtime.{self.implementation}.memory", + f"process.runtime.{self.implementation}.cpu_time", + f"process.runtime.{self.implementation}.gc_count", ] for observer in metric_names: @@ -125,9 +125,9 @@ def test_system_metrics_instrument(self): def test_runtime_metrics_instrument(self): runtime_config = { - "runtime.memory": ["rss", "vms"], - "runtime.cpu.time": ["user", "system"], - "runtime.gc_count": None, + "process.runtime.memory": ["rss", "vms"], + "process.runtime.cpu.time": ["user", "system"], + "process.runtime.gc_count": None, } reader = InMemoryMetricReader() @@ -143,9 +143,9 @@ def test_runtime_metrics_instrument(self): self.assertEqual(len(metric_names), 3) observer_names = [ - f"runtime.{self.implementation}.memory", - f"runtime.{self.implementation}.cpu_time", - f"runtime.{self.implementation}.gc_count", + f"process.runtime.{self.implementation}.memory", + f"process.runtime.{self.implementation}.cpu_time", + f"process.runtime.{self.implementation}.gc_count", ] for observer in metric_names: @@ -750,7 +750,7 @@ def test_runtime_memory(self, mock_process_memory_info): _SystemMetricsResult({"type": "rss"}, 1), _SystemMetricsResult({"type": "vms"}, 2), ] - self._test_metrics(f"runtime.{self.implementation}.memory", expected) + self._test_metrics(f"process.runtime.{self.implementation}.memory", expected) @mock.patch("psutil.Process.cpu_times") def test_runtime_cpu_time(self, mock_process_cpu_times): @@ -764,7 +764,7 @@ def test_runtime_cpu_time(self, mock_process_cpu_times): _SystemMetricsResult({"type": "user"}, 1.1), _SystemMetricsResult({"type": "system"}, 2.2), ] - self._test_metrics(f"runtime.{self.implementation}.cpu_time", expected) + self._test_metrics(f"process.runtime.{self.implementation}.cpu_time", expected) @mock.patch("gc.get_count") def test_runtime_get_count(self, mock_gc_get_count): @@ -775,4 +775,4 @@ def test_runtime_get_count(self, mock_gc_get_count): _SystemMetricsResult({"count": "1"}, 2), _SystemMetricsResult({"count": "2"}, 3), ] - self._test_metrics(f"runtime.{self.implementation}.gc_count", expected) + self._test_metrics(f"process.runtime.{self.implementation}.gc_count", expected) From 57cadb4d1aa902cd654dfd9c87681db30eb79824 Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Thu, 30 Mar 2023 11:49:12 -0400 Subject: [PATCH 5/6] Lint changes --- .../tests/test_system_metrics.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 de12f6d73a..f6dbd6c9a1 100644 --- a/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py +++ b/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py @@ -750,7 +750,9 @@ def test_runtime_memory(self, mock_process_memory_info): _SystemMetricsResult({"type": "rss"}, 1), _SystemMetricsResult({"type": "vms"}, 2), ] - self._test_metrics(f"process.runtime.{self.implementation}.memory", expected) + self._test_metrics( + f"process.runtime.{self.implementation}.memory", expected + ) @mock.patch("psutil.Process.cpu_times") def test_runtime_cpu_time(self, mock_process_cpu_times): @@ -764,7 +766,9 @@ def test_runtime_cpu_time(self, mock_process_cpu_times): _SystemMetricsResult({"type": "user"}, 1.1), _SystemMetricsResult({"type": "system"}, 2.2), ] - self._test_metrics(f"process.runtime.{self.implementation}.cpu_time", expected) + self._test_metrics( + f"process.runtime.{self.implementation}.cpu_time", expected + ) @mock.patch("gc.get_count") def test_runtime_get_count(self, mock_gc_get_count): @@ -775,4 +779,6 @@ def test_runtime_get_count(self, mock_gc_get_count): _SystemMetricsResult({"count": "1"}, 2), _SystemMetricsResult({"count": "2"}, 3), ] - self._test_metrics(f"process.runtime.{self.implementation}.gc_count", expected) + self._test_metrics( + f"process.runtime.{self.implementation}.gc_count", expected + ) From 7d6b0df8093954378add4b0bc160e08767f709c9 Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Mon, 3 Apr 2023 10:50:33 -0400 Subject: [PATCH 6/6] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38a36e6944..981d2fd232 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- `opentelemetry-instrumentation-system-metrics` Add `process.` prefix to `runtime.memory`, `runtime.cpu.time`, and `runtime.gc_count`. Change `runtime.memory` from count to UpDownCounter. ([#1735](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1735)) + ### Added - Add `excluded_urls` functionality to `urllib` and `urllib3` instrumentations @@ -43,7 +45,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-instrumentation-requests` Replace `name_callback` and `span_callback` with standard `response_hook` and `request_hook` callbacks ([#670](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/670)) -- `opentelemetry-instrumentation-system-metrics` Add `process.` prefix to `runtime.memory`, `runtime.cpu.time`, and `runtime.gc_count`. Change `runtime.memory` from count to UpDownCounter. ([#1735](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1735)) ## Version 1.16.0/0.37b0 (2023-02-17)