Skip to content

Commit b4ffc63

Browse files
authored
Merge branch 'main' into feature/asyncio-instrumentation
2 parents 7e40c0b + f347716 commit b4ffc63

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
([#1980](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1980))
3333
- `opentelemetry-resource-detector-azure` Using new Cloud Resource ID attribute.
3434
([#1976](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1976))
35+
- Do not collect `system.network.connections` by default on macOS which was causing exceptions in metrics collection.
36+
([#2008](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2008))
3537

3638
## Version 1.20.0/0.41b0 (2023-09-01)
3739

@@ -1395,6 +1397,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13951397
- `opentelemetry-ext-wsgi` Updates for core library changes
13961398
- `opentelemetry-ext-http-requests` Updates for core library changes
13971399

1400+
- `Added support for PyPy3` Initial release
1401+
## [#1033](https://github.com/open-telemetryopentelemetry-python-contrib/issues/1033)
1402+
13981403
## Version 0.1a0 (2019-09-30)
13991404

14001405
### Added

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

+21-6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777

7878
import gc
7979
import os
80+
import sys
81+
import logging
8082
import threading
8183
from platform import python_implementation
8284
from typing import Collection, Dict, Iterable, List, Optional
@@ -91,6 +93,9 @@
9193
from opentelemetry.metrics import CallbackOptions, Observation, get_meter
9294
from opentelemetry.sdk.util import get_dict_as_key
9395

96+
_logger = logging.getLogger(__name__)
97+
98+
9499
_DEFAULT_CONFIG = {
95100
"system.cpu.time": ["idle", "user", "system", "irq"],
96101
"system.cpu.utilization": ["idle", "user", "system", "irq"],
@@ -115,6 +120,10 @@
115120
"process.runtime.context_switches": ["involuntary", "voluntary"],
116121
}
117122

123+
if sys.platform == "darwin":
124+
# see https://github.com/giampaolo/psutil/issues/1219
125+
_DEFAULT_CONFIG.pop("system.network.connections")
126+
118127

119128
class SystemMetricsInstrumentor(BaseInstrumentor):
120129
def __init__(
@@ -352,12 +361,18 @@ def _instrument(self, **kwargs):
352361
)
353362

354363
if "process.runtime.gc_count" in self._config:
355-
self._meter.create_observable_counter(
356-
name=f"process.runtime.{self._python_implementation}.gc_count",
357-
callbacks=[self._get_runtime_gc_count],
358-
description=f"Runtime {self._python_implementation} GC count",
359-
unit="bytes",
360-
)
364+
if self._python_implementation == "pypy":
365+
_logger.warning(
366+
"The process.runtime.gc_count metric won't be collected because the interpreter is PyPy"
367+
)
368+
else:
369+
self._meter.create_observable_counter(
370+
name=f"process.runtime.{self._python_implementation}.gc_count",
371+
callbacks=[self._get_runtime_gc_count],
372+
description=f"Runtime {self._python_implementation} GC count",
373+
unit="bytes",
374+
)
375+
361376

362377
if "process.runtime.thread_count" in self._config:
363378
self._meter.create_observable_up_down_counter(

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

+17-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from collections import namedtuple
1818
from platform import python_implementation
19-
from unittest import mock
19+
from unittest import mock, skipIf
2020

2121
from opentelemetry.sdk.metrics import MeterProvider
2222
from opentelemetry.sdk.metrics.export import InMemoryMetricReader
@@ -97,7 +97,6 @@ def test_system_metrics_instrument(self):
9797
for scope_metrics in resource_metrics.scope_metrics:
9898
for metric in scope_metrics.metrics:
9999
metric_names.append(metric.name)
100-
self.assertEqual(len(metric_names), 21)
101100

102101
observer_names = [
103102
"system.cpu.time",
@@ -117,11 +116,16 @@ def test_system_metrics_instrument(self):
117116
"system.thread_count",
118117
f"process.runtime.{self.implementation}.memory",
119118
f"process.runtime.{self.implementation}.cpu_time",
120-
f"process.runtime.{self.implementation}.gc_count",
121119
f"process.runtime.{self.implementation}.thread_count",
122120
f"process.runtime.{self.implementation}.context_switches",
123121
f"process.runtime.{self.implementation}.cpu.utilization",
124122
]
123+
124+
if self.implementation == "pypy":
125+
self.assertEqual(len(metric_names), 20)
126+
else:
127+
self.assertEqual(len(metric_names), 21)
128+
observer_names.append(f"process.runtime.{self.implementation}.gc_count",)
125129

126130
for observer in metric_names:
127131
self.assertIn(observer, observer_names)
@@ -131,11 +135,13 @@ def test_runtime_metrics_instrument(self):
131135
runtime_config = {
132136
"process.runtime.memory": ["rss", "vms"],
133137
"process.runtime.cpu.time": ["user", "system"],
134-
"process.runtime.gc_count": None,
135138
"process.runtime.thread_count": None,
136139
"process.runtime.cpu.utilization": None,
137140
"process.runtime.context_switches": ["involuntary", "voluntary"],
138141
}
142+
143+
if self.implementation != "pypy":
144+
runtime_config["process.runtime.gc_count"] = None
139145

140146
reader = InMemoryMetricReader()
141147
meter_provider = MeterProvider(metric_readers=[reader])
@@ -147,17 +153,21 @@ def test_runtime_metrics_instrument(self):
147153
for scope_metrics in resource_metrics.scope_metrics:
148154
for metric in scope_metrics.metrics:
149155
metric_names.append(metric.name)
150-
self.assertEqual(len(metric_names), 6)
151156

152157
observer_names = [
153158
f"process.runtime.{self.implementation}.memory",
154159
f"process.runtime.{self.implementation}.cpu_time",
155-
f"process.runtime.{self.implementation}.gc_count",
156160
f"process.runtime.{self.implementation}.thread_count",
157161
f"process.runtime.{self.implementation}.context_switches",
158162
f"process.runtime.{self.implementation}.cpu.utilization",
159163
]
160164

165+
if self.implementation == "pypy":
166+
self.assertEqual(len(metric_names), 5)
167+
else:
168+
self.assertEqual(len(metric_names), 6)
169+
observer_names.append(f"process.runtime.{self.implementation}.gc_count")
170+
161171
for observer in metric_names:
162172
self.assertIn(observer, observer_names)
163173
observer_names.remove(observer)
@@ -781,6 +791,7 @@ def test_runtime_cpu_time(self, mock_process_cpu_times):
781791
)
782792

783793
@mock.patch("gc.get_count")
794+
@skipIf(python_implementation().lower() == "pypy", "not supported for pypy")
784795
def test_runtime_get_count(self, mock_gc_get_count):
785796
mock_gc_get_count.configure_mock(**{"return_value": (1, 2, 3)})
786797

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ envlist =
194194

195195
; opentelemetry-instrumentation-system-metrics
196196
py3{6,7,8,9,10,11}-test-instrumentation-system-metrics
197-
; instrumentation-system-metrics intentionally excluded from pypy3
197+
pypy3-test-instrumentation-system-metrics
198198

199199
; opentelemetry-instrumentation-tornado
200200
py3{7,8,9,10,11}-test-instrumentation-tornado

0 commit comments

Comments
 (0)