From e4a1b108bb8ded8d6f09268e8a782fcd660bf467 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 7 Jan 2026 11:00:34 +0000 Subject: [PATCH 1/2] Initial plan From 996c805dfbe6184277ea7c98cbed29139267e498 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 7 Jan 2026 11:18:48 +0000 Subject: [PATCH 2/2] Fix cpython.gc metrics to use correct attribute name - Import CPYTHON_GC_GENERATION from semantic conventions - Replace "generation" with CPYTHON_GC_GENERATION constant - Change generation values from strings to integers (0, 1, 2) - Update tests to use correct attribute name "cpython.gc.generation" Co-authored-by: xrmx <12932+xrmx@users.noreply.github.com> --- .../instrumentation/system_metrics/__init__.py | 13 ++++++++----- .../tests/test_system_metrics.py | 18 +++++++++--------- 2 files changed, 17 insertions(+), 14 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 e0e425aada..272b3ce9c9 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 @@ -112,6 +112,9 @@ from opentelemetry.instrumentation.system_metrics.package import _instruments from opentelemetry.instrumentation.system_metrics.version import __version__ from opentelemetry.metrics import CallbackOptions, Observation, get_meter +from opentelemetry.semconv._incubating.attributes.cpython_attributes import ( + CPYTHON_GC_GENERATION, +) from opentelemetry.semconv._incubating.metrics.process_metrics import ( create_process_cpu_utilization, ) @@ -958,7 +961,7 @@ def _get_runtime_gc_collections( ) -> Iterable[Observation]: """Observer callback for garbage collection""" for index, stat in enumerate(gc.get_stats()): - self._runtime_gc_collections_labels["generation"] = str(index) + self._runtime_gc_collections_labels[CPYTHON_GC_GENERATION] = index yield Observation( stat["collections"], self._runtime_gc_collections_labels.copy() ) @@ -968,7 +971,7 @@ def _get_runtime_gc_collected_objects( ) -> Iterable[Observation]: """Observer callback for garbage collection collected objects""" for index, stat in enumerate(gc.get_stats()): - self._runtime_gc_collected_objects_labels["generation"] = str( + self._runtime_gc_collected_objects_labels[CPYTHON_GC_GENERATION] = ( index ) yield Observation( @@ -981,9 +984,9 @@ def _get_runtime_gc_uncollectable_objects( ) -> Iterable[Observation]: """Observer callback for garbage collection uncollectable objects""" for index, stat in enumerate(gc.get_stats()): - self._runtime_gc_uncollectable_objects_labels["generation"] = str( - index - ) + self._runtime_gc_uncollectable_objects_labels[ + CPYTHON_GC_GENERATION + ] = index yield Observation( stat["uncollectable"], self._runtime_gc_uncollectable_objects_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 ef110c3da1..151167bee8 100644 --- a/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py +++ b/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py @@ -983,9 +983,9 @@ def test_runtime_get_gc_collections(self, mock_gc_get_stats): } ) expected_gc_collections = [ - _SystemMetricsResult({"generation": "0"}, 10), - _SystemMetricsResult({"generation": "1"}, 20), - _SystemMetricsResult({"generation": "2"}, 30), + _SystemMetricsResult({"cpython.gc.generation": 0}, 10), + _SystemMetricsResult({"cpython.gc.generation": 1}, 20), + _SystemMetricsResult({"cpython.gc.generation": 2}, 30), ] self._test_metrics( "cpython.gc.collections", @@ -1007,9 +1007,9 @@ def test_runtime_get_gc_collected_objects(self, mock_gc_get_stats): } ) expected_gc_collected_objects = [ - _SystemMetricsResult({"generation": "0"}, 100), - _SystemMetricsResult({"generation": "1"}, 200), - _SystemMetricsResult({"generation": "2"}, 300), + _SystemMetricsResult({"cpython.gc.generation": 0}, 100), + _SystemMetricsResult({"cpython.gc.generation": 1}, 200), + _SystemMetricsResult({"cpython.gc.generation": 2}, 300), ] self._test_metrics( "cpython.gc.collected_objects", @@ -1031,9 +1031,9 @@ def test_runtime_get_gc_uncollectable_objects(self, mock_gc_get_stats): } ) expected_gc_uncollectable_objects = [ - _SystemMetricsResult({"generation": "0"}, 1), - _SystemMetricsResult({"generation": "1"}, 2), - _SystemMetricsResult({"generation": "2"}, 3), + _SystemMetricsResult({"cpython.gc.generation": 0}, 1), + _SystemMetricsResult({"cpython.gc.generation": 1}, 2), + _SystemMetricsResult({"cpython.gc.generation": 2}, 3), ] self._test_metrics( "cpython.gc.uncollectable_objects",