Skip to content

Commit 4003bb0

Browse files
committed
round
1 parent 9c514f8 commit 4003bb0

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
([#3567](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3567))
3030
- `opentelemetry-resource-detector-containerid`: make it more quiet on platforms without cgroups
3131
([#3579](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3579))
32-
- `opentelemetry-instrumentation-system-metrics`: Add process.runtime.cpython.gc_count metrics with collection unit is specified in semconv ([3617](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3617))
32+
- `opentelemetry-instrumentation-system-metrics`: Add cpython.gc.collections metrics with collection unit is specified in semconv ([3617](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3617))
3333

3434
## Version 1.34.0/0.55b0 (2025-06-04)
3535

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"process.runtime.memory": ["rss", "vms"],
4545
"process.runtime.cpu.time": ["user", "system"],
4646
"process.runtime.gc_count": None,
47+
"cpython.gc.collections": None,
4748
"process.runtime.thread_count": None,
4849
"process.runtime.cpu.utilization": None,
4950
"process.runtime.context_switches": ["involuntary", "voluntary"],
@@ -136,6 +137,7 @@
136137
"process.runtime.memory": ["rss", "vms"],
137138
"process.runtime.cpu.time": ["user", "system"],
138139
"process.runtime.gc_count": None,
140+
"cpython.gc.collections": None,
139141
"process.runtime.thread_count": None,
140142
"process.runtime.cpu.utilization": None,
141143
"process.runtime.context_switches": ["involuntary", "voluntary"],
@@ -470,8 +472,15 @@ def _instrument(self, **kwargs: Any):
470472
description=f"Runtime {self._python_implementation} GC count",
471473
unit="By",
472474
)
475+
476+
if "cpython.gc.collections" in self._config:
477+
if self._python_implementation == "pypy":
478+
_logger.warning(
479+
"The cpython.gc.collections metric won't be collected because the interpreter is PyPy"
480+
)
481+
else:
473482
self._meter.create_observable_counter(
474-
name=f"process.runtime.{self._python_implementation}.gc_count",
483+
name="cpython.gc.collections",
475484
callbacks=[self._get_runtime_gc_collections],
476485
description="The number of times a generation was collected since interpreter start.",
477486
unit="{collection}",

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def test_system_metrics_instrument(self):
137137
f"process.runtime.{self.implementation}.gc_count",
138138
)
139139
observer_names.append(
140-
f"process.runtime.{self.implementation}.gc_count",
140+
"cpython.gc.collections",
141141
)
142142
if sys.platform != "darwin":
143143
observer_names.append("system.network.connections")
@@ -958,30 +958,21 @@ def test_runtime_get_count(self, mock_gc_get_count):
958958
f"process.runtime.{self.implementation}.gc_count",
959959
expected_gc_count,
960960
)
961-
expected_gc_collections = [
962-
_SystemMetricsResult({"generation": "0"}, 1),
963-
_SystemMetricsResult({"generation": "1"}, 2),
964-
_SystemMetricsResult({"generation": "2"}, 3),
965-
]
966-
self._test_metrics(
967-
f"process.runtime.{self.implementation}.gc_collections",
968-
expected_gc_collections,
969-
)
970961

971962
@mock.patch("gc.get_count")
972963
@skipIf(
973964
python_implementation().lower() == "pypy", "not supported for pypy"
974965
)
975-
def test_runtime_get_count(self, mock_gc_get_count):
966+
def test_runtime_get_gc_collections(self, mock_gc_get_count):
976967
mock_gc_get_count.configure_mock(**{"return_value": (1, 2, 3)})
977-
978-
expected = [
979-
_SystemMetricsResult({"count": "0"}, 1),
980-
_SystemMetricsResult({"count": "1"}, 2),
981-
_SystemMetricsResult({"count": "2"}, 3),
968+
expected_gc_collections = [
969+
_SystemMetricsResult({"generation": "0"}, 1),
970+
_SystemMetricsResult({"generation": "1"}, 2),
971+
_SystemMetricsResult({"generation": "2"}, 3),
982972
]
983973
self._test_metrics(
984-
f"process.runtime.{self.implementation}.gc_count", expected
974+
"cpython.gc.collections",
975+
expected_gc_collections,
985976
)
986977

987978
@mock.patch("psutil.Process.num_ctx_switches")

0 commit comments

Comments
 (0)