Skip to content

Commit

Permalink
Merge branch 'main' into cleanup-suppress
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen committed Nov 20, 2023
2 parents 7de7508 + 9afaf26 commit 6ad4cf7
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 19 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Consolidate instrumentation suppression mechanisms and fix bug in httpx instrumentation
([#2061](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2061))

### Fixed

- `opentelemetry-instrumentation-urllib`/`opentelemetry-instrumentation-urllib3` Fix metric descriptions to match semantic conventions
([#1959]((https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1959))

## Version 1.21.0/0.42b0 (2023-11-01)

### Added
Expand All @@ -33,6 +38,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1980](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1980))
- `opentelemetry-resource-detector-azure` Using new Cloud Resource ID attribute.
([#1976](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1976))
- Do not collect `system.network.connections` by default on macOS which was causing exceptions in metrics collection.
([#2008](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2008))

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

Expand Down Expand Up @@ -1396,6 +1403,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@

import gc
import os
import sys
import logging
import threading
from platform import python_implementation
from typing import Collection, Dict, Iterable, List, Optional
Expand All @@ -91,6 +93,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"],
Expand All @@ -115,6 +120,10 @@
"process.runtime.context_switches": ["involuntary", "voluntary"],
}

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


class SystemMetricsInstrumentor(BaseInstrumentor):
def __init__(
Expand Down Expand Up @@ -352,12 +361,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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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])
Expand All @@ -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)
Expand Down Expand Up @@ -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)})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,17 @@ def _create_client_histograms(meter) -> Dict[str, Histogram]:
MetricInstruments.HTTP_CLIENT_DURATION: meter.create_histogram(
name=MetricInstruments.HTTP_CLIENT_DURATION,
unit="ms",
description="measures the duration outbound HTTP requests",
description="Measures the duration of outbound HTTP requests.",
),
MetricInstruments.HTTP_CLIENT_REQUEST_SIZE: meter.create_histogram(
name=MetricInstruments.HTTP_CLIENT_REQUEST_SIZE,
unit="By",
description="measures the size of HTTP request messages (compressed)",
description="Measures the size of HTTP request messages.",
),
MetricInstruments.HTTP_CLIENT_RESPONSE_SIZE: meter.create_histogram(
name=MetricInstruments.HTTP_CLIENT_RESPONSE_SIZE,
unit="By",
description="measures the size of HTTP response messages (compressed)",
description="Measures the size of HTTP response messages.",
),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,17 @@ def _instrument(self, **kwargs):
duration_histogram = meter.create_histogram(
name=MetricInstruments.HTTP_CLIENT_DURATION,
unit="ms",
description="measures the duration outbound HTTP requests",
description="Measures the duration of outbound HTTP requests.",
)
request_size_histogram = meter.create_histogram(
name=MetricInstruments.HTTP_CLIENT_REQUEST_SIZE,
unit="By",
description="measures the size of HTTP request messages (compressed)",
description="Measures the size of HTTP request messages.",
)
response_size_histogram = meter.create_histogram(
name=MetricInstruments.HTTP_CLIENT_RESPONSE_SIZE,
unit="By",
description="measures the size of HTTP response messages (compressed)",
description="Measures the size of HTTP response messages.",
)

_instrument(
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6ad4cf7

Please sign in to comment.