mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-28 20:52:57 +08:00
Added support for pypy3 system metrics (#2062)
* Added support for pypy3 system metrics Co-authored-by: Suryanarayana Peri <suryanarayana.peri@fmr.com> Signed-off-by: Rahul Kumar <Rahul.Kumar@fmr.com> * Change in if condition to log warn message for pypy Co-authored-by: Suryanarayana Peri <suryanarayana.peri@fmr.com> Signed-off-by: Rahul Kumar <Rahul.Kumar@fmr.com> * Added logger to else block if pypy Co-authored-by: Suryanarayana Peri <suryanarayana.peri@fmr.com> Signed-off-by: Rahul Kumar <Rahul.Kumar@fmr.com> * Reverting the changes Co-authored-by: Suryanarayana Peri <suryanarayana.peri@fmr.com> Signed-off-by: Rahul Kumar <Rahul.Kumar@fmr.com> * Changes requested by external reviewer Co-authored-by: Suryanarayana Peri <suryanarayana.peri@fmr.com> Signed-off-by: Rahul Kumar <Rahul.Kumar@fmr.com> --------- Signed-off-by: Rahul Kumar <Rahul.Kumar@fmr.com> Co-authored-by: Suryanarayana Peri <suryanarayana.peri@fmr.com>
This commit is contained in:
@ -1394,6 +1394,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-wsgi` Updates for core library changes
|
||||||
- `opentelemetry-ext-http-requests` 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)
|
## Version 0.1a0 (2019-09-30)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -77,6 +77,7 @@ API
|
|||||||
|
|
||||||
import gc
|
import gc
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
import threading
|
import threading
|
||||||
from platform import python_implementation
|
from platform import python_implementation
|
||||||
from typing import Collection, Dict, Iterable, List, Optional
|
from typing import Collection, Dict, Iterable, List, Optional
|
||||||
@ -91,6 +92,9 @@ from opentelemetry.instrumentation.system_metrics.version import __version__
|
|||||||
from opentelemetry.metrics import CallbackOptions, Observation, get_meter
|
from opentelemetry.metrics import CallbackOptions, Observation, get_meter
|
||||||
from opentelemetry.sdk.util import get_dict_as_key
|
from opentelemetry.sdk.util import get_dict_as_key
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
_DEFAULT_CONFIG = {
|
_DEFAULT_CONFIG = {
|
||||||
"system.cpu.time": ["idle", "user", "system", "irq"],
|
"system.cpu.time": ["idle", "user", "system", "irq"],
|
||||||
"system.cpu.utilization": ["idle", "user", "system", "irq"],
|
"system.cpu.utilization": ["idle", "user", "system", "irq"],
|
||||||
@ -352,12 +356,18 @@ class SystemMetricsInstrumentor(BaseInstrumentor):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if "process.runtime.gc_count" in self._config:
|
if "process.runtime.gc_count" in self._config:
|
||||||
self._meter.create_observable_counter(
|
if self._python_implementation == "pypy":
|
||||||
name=f"process.runtime.{self._python_implementation}.gc_count",
|
_logger.warning(
|
||||||
callbacks=[self._get_runtime_gc_count],
|
"The process.runtime.gc_count metric won't be collected because the interpreter is PyPy"
|
||||||
description=f"Runtime {self._python_implementation} GC count",
|
)
|
||||||
unit="bytes",
|
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:
|
if "process.runtime.thread_count" in self._config:
|
||||||
self._meter.create_observable_up_down_counter(
|
self._meter.create_observable_up_down_counter(
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from platform import python_implementation
|
from platform import python_implementation
|
||||||
from unittest import mock
|
from unittest import mock, skipIf
|
||||||
|
|
||||||
from opentelemetry.sdk.metrics import MeterProvider
|
from opentelemetry.sdk.metrics import MeterProvider
|
||||||
from opentelemetry.sdk.metrics.export import InMemoryMetricReader
|
from opentelemetry.sdk.metrics.export import InMemoryMetricReader
|
||||||
@ -97,7 +97,6 @@ class TestSystemMetrics(TestBase):
|
|||||||
for scope_metrics in resource_metrics.scope_metrics:
|
for scope_metrics in resource_metrics.scope_metrics:
|
||||||
for metric in scope_metrics.metrics:
|
for metric in scope_metrics.metrics:
|
||||||
metric_names.append(metric.name)
|
metric_names.append(metric.name)
|
||||||
self.assertEqual(len(metric_names), 21)
|
|
||||||
|
|
||||||
observer_names = [
|
observer_names = [
|
||||||
"system.cpu.time",
|
"system.cpu.time",
|
||||||
@ -117,11 +116,16 @@ class TestSystemMetrics(TestBase):
|
|||||||
"system.thread_count",
|
"system.thread_count",
|
||||||
f"process.runtime.{self.implementation}.memory",
|
f"process.runtime.{self.implementation}.memory",
|
||||||
f"process.runtime.{self.implementation}.cpu_time",
|
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}.thread_count",
|
||||||
f"process.runtime.{self.implementation}.context_switches",
|
f"process.runtime.{self.implementation}.context_switches",
|
||||||
f"process.runtime.{self.implementation}.cpu.utilization",
|
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:
|
for observer in metric_names:
|
||||||
self.assertIn(observer, observer_names)
|
self.assertIn(observer, observer_names)
|
||||||
@ -131,11 +135,13 @@ class TestSystemMetrics(TestBase):
|
|||||||
runtime_config = {
|
runtime_config = {
|
||||||
"process.runtime.memory": ["rss", "vms"],
|
"process.runtime.memory": ["rss", "vms"],
|
||||||
"process.runtime.cpu.time": ["user", "system"],
|
"process.runtime.cpu.time": ["user", "system"],
|
||||||
"process.runtime.gc_count": None,
|
|
||||||
"process.runtime.thread_count": None,
|
"process.runtime.thread_count": None,
|
||||||
"process.runtime.cpu.utilization": None,
|
"process.runtime.cpu.utilization": None,
|
||||||
"process.runtime.context_switches": ["involuntary", "voluntary"],
|
"process.runtime.context_switches": ["involuntary", "voluntary"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.implementation != "pypy":
|
||||||
|
runtime_config["process.runtime.gc_count"] = None
|
||||||
|
|
||||||
reader = InMemoryMetricReader()
|
reader = InMemoryMetricReader()
|
||||||
meter_provider = MeterProvider(metric_readers=[reader])
|
meter_provider = MeterProvider(metric_readers=[reader])
|
||||||
@ -147,17 +153,21 @@ class TestSystemMetrics(TestBase):
|
|||||||
for scope_metrics in resource_metrics.scope_metrics:
|
for scope_metrics in resource_metrics.scope_metrics:
|
||||||
for metric in scope_metrics.metrics:
|
for metric in scope_metrics.metrics:
|
||||||
metric_names.append(metric.name)
|
metric_names.append(metric.name)
|
||||||
self.assertEqual(len(metric_names), 6)
|
|
||||||
|
|
||||||
observer_names = [
|
observer_names = [
|
||||||
f"process.runtime.{self.implementation}.memory",
|
f"process.runtime.{self.implementation}.memory",
|
||||||
f"process.runtime.{self.implementation}.cpu_time",
|
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}.thread_count",
|
||||||
f"process.runtime.{self.implementation}.context_switches",
|
f"process.runtime.{self.implementation}.context_switches",
|
||||||
f"process.runtime.{self.implementation}.cpu.utilization",
|
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:
|
for observer in metric_names:
|
||||||
self.assertIn(observer, observer_names)
|
self.assertIn(observer, observer_names)
|
||||||
observer_names.remove(observer)
|
observer_names.remove(observer)
|
||||||
@ -781,6 +791,7 @@ class TestSystemMetrics(TestBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch("gc.get_count")
|
@mock.patch("gc.get_count")
|
||||||
|
@skipIf(python_implementation().lower() == "pypy", "not supported for pypy")
|
||||||
def test_runtime_get_count(self, mock_gc_get_count):
|
def test_runtime_get_count(self, mock_gc_get_count):
|
||||||
mock_gc_get_count.configure_mock(**{"return_value": (1, 2, 3)})
|
mock_gc_get_count.configure_mock(**{"return_value": (1, 2, 3)})
|
||||||
|
|
||||||
|
2
tox.ini
2
tox.ini
@ -194,7 +194,7 @@ envlist =
|
|||||||
|
|
||||||
; opentelemetry-instrumentation-system-metrics
|
; opentelemetry-instrumentation-system-metrics
|
||||||
py3{6,7,8,9,10,11}-test-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
|
; opentelemetry-instrumentation-tornado
|
||||||
py3{7,8,9,10,11}-test-instrumentation-tornado
|
py3{7,8,9,10,11}-test-instrumentation-tornado
|
||||||
|
Reference in New Issue
Block a user