diff --git a/CHANGELOG.md b/CHANGELOG.md index 4db0841147..41da49df14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1396,6 +1396,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-ext-wsgi` Updates for core library changes - `opentelemetry-ext-http-requests` Updates for core library changes +- `Added support for PyPy3` Initial release +## [#1033](https://github.com/open-telemetryopentelemetry-python-contrib/issues/1033) + ## Version 0.1a0 (2019-09-30) ### Added 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 e97685ba74..56d07f4e63 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 @@ -77,6 +77,7 @@ import gc import os +import logging import threading from platform import python_implementation from typing import Collection, Dict, Iterable, List, Optional @@ -91,6 +92,9 @@ from opentelemetry.metrics import CallbackOptions, Observation, get_meter from opentelemetry.sdk.util import get_dict_as_key +_logger = logging.getLogger(__name__) + + _DEFAULT_CONFIG = { "system.cpu.time": ["idle", "user", "system", "irq"], "system.cpu.utilization": ["idle", "user", "system", "irq"], @@ -352,12 +356,18 @@ def _instrument(self, **kwargs): ) if "process.runtime.gc_count" in self._config: - self._meter.create_observable_counter( - 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", - ) + if self._python_implementation == "pypy": + _logger.warning( + "The process.runtime.gc_count metric won't be collected because the interpreter is PyPy" + ) + else: + self._meter.create_observable_counter( + 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", + ) + if "process.runtime.thread_count" in self._config: self._meter.create_observable_up_down_counter( 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 e28c437009..064a1534a6 100644 --- a/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py +++ b/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py @@ -16,7 +16,7 @@ from collections import namedtuple from platform import python_implementation -from unittest import mock +from unittest import mock, skipIf from opentelemetry.sdk.metrics import MeterProvider from opentelemetry.sdk.metrics.export import InMemoryMetricReader @@ -97,7 +97,6 @@ def test_system_metrics_instrument(self): for scope_metrics in resource_metrics.scope_metrics: for metric in scope_metrics.metrics: metric_names.append(metric.name) - self.assertEqual(len(metric_names), 21) observer_names = [ "system.cpu.time", @@ -117,11 +116,16 @@ def test_system_metrics_instrument(self): "system.thread_count", f"process.runtime.{self.implementation}.memory", f"process.runtime.{self.implementation}.cpu_time", - f"process.runtime.{self.implementation}.gc_count", f"process.runtime.{self.implementation}.thread_count", f"process.runtime.{self.implementation}.context_switches", f"process.runtime.{self.implementation}.cpu.utilization", ] + + if self.implementation == "pypy": + self.assertEqual(len(metric_names), 20) + else: + self.assertEqual(len(metric_names), 21) + observer_names.append(f"process.runtime.{self.implementation}.gc_count",) for observer in metric_names: self.assertIn(observer, observer_names) @@ -131,11 +135,13 @@ def test_runtime_metrics_instrument(self): runtime_config = { "process.runtime.memory": ["rss", "vms"], "process.runtime.cpu.time": ["user", "system"], - "process.runtime.gc_count": None, "process.runtime.thread_count": None, "process.runtime.cpu.utilization": None, "process.runtime.context_switches": ["involuntary", "voluntary"], } + + if self.implementation != "pypy": + runtime_config["process.runtime.gc_count"] = None reader = InMemoryMetricReader() meter_provider = MeterProvider(metric_readers=[reader]) @@ -147,17 +153,21 @@ def test_runtime_metrics_instrument(self): for scope_metrics in resource_metrics.scope_metrics: for metric in scope_metrics.metrics: metric_names.append(metric.name) - self.assertEqual(len(metric_names), 6) observer_names = [ f"process.runtime.{self.implementation}.memory", f"process.runtime.{self.implementation}.cpu_time", - f"process.runtime.{self.implementation}.gc_count", f"process.runtime.{self.implementation}.thread_count", f"process.runtime.{self.implementation}.context_switches", f"process.runtime.{self.implementation}.cpu.utilization", ] + if self.implementation == "pypy": + self.assertEqual(len(metric_names), 5) + else: + self.assertEqual(len(metric_names), 6) + observer_names.append(f"process.runtime.{self.implementation}.gc_count") + for observer in metric_names: self.assertIn(observer, observer_names) observer_names.remove(observer) @@ -781,6 +791,7 @@ def test_runtime_cpu_time(self, mock_process_cpu_times): ) @mock.patch("gc.get_count") + @skipIf(python_implementation().lower() == "pypy", "not supported for pypy") def test_runtime_get_count(self, mock_gc_get_count): mock_gc_get_count.configure_mock(**{"return_value": (1, 2, 3)}) diff --git a/tox.ini b/tox.ini index 2eaef92404..2527613c54 100644 --- a/tox.ini +++ b/tox.ini @@ -194,7 +194,7 @@ envlist = ; opentelemetry-instrumentation-system-metrics py3{6,7,8,9,10,11}-test-instrumentation-system-metrics - ; instrumentation-system-metrics intentionally excluded from pypy3 + pypy3-test-instrumentation-system-metrics ; opentelemetry-instrumentation-tornado py3{7,8,9,10,11}-test-instrumentation-tornado