Skip to content

Commit

Permalink
Make metrics api/sdk packages private *._metrics (#2249)
Browse files Browse the repository at this point in the history
* Make metrics api/sdk packages private `*._metrics`

* add warning
  • Loading branch information
aabmass authored Oct 29, 2021
1 parent 7539592 commit ef978ad
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 38 deletions.
6 changes: 3 additions & 3 deletions docs/api/metrics.instrument.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
opentelemetry.metrics.instrument
================================
opentelemetry._metrics.instrument
=================================

.. automodule:: opentelemetry.metrics.instrument
.. automodule:: opentelemetry._metrics.instrument
:members:
:private-members:
:undoc-members:
Expand Down
6 changes: 3 additions & 3 deletions docs/api/metrics.measurement.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
opentelemetry.metrics.measurement
=================================
opentelemetry._metrics.measurement
==================================

.. automodule:: opentelemetry.metrics.measurement
.. automodule:: opentelemetry._metrics.measurement
:members:
:undoc-members:
:show-inheritance:
13 changes: 10 additions & 3 deletions docs/api/metrics.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
opentelemetry.metrics package
=============================
opentelemetry._metrics package
==============================

.. warning::
OpenTelemetry Python metrics are in an experimental state. The APIs within
:mod:`opentelemetry._metrics` are subject to change in minor/patch releases and make no
backward compatability guarantees at this time.

Once metrics become stable, this package will be be renamed to ``opentelemetry.metrics``.

Submodules
----------
Expand All @@ -12,4 +19,4 @@ Submodules
Module contents
---------------

.. automodule:: opentelemetry.metrics
.. automodule:: opentelemetry._metrics
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
("py:class", "ValueT"),
("py:class", "MetricT"),
("py:class", "InstrumentT"),
("py:obj", "opentelemetry.metrics.instrument.InstrumentT"),
("py:obj", "opentelemetry._metrics.instrument.InstrumentT"),
# Even if wrapt is added to intersphinx_mapping, sphinx keeps failing
# with "class reference target not found: ObjectProxy".
("py:class", "ObjectProxy"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
from threading import Lock
from typing import List, Optional, cast

from opentelemetry.environment_variables import OTEL_PYTHON_METER_PROVIDER
from opentelemetry.metrics.instrument import (
from opentelemetry._metrics.instrument import (
Counter,
DefaultCounter,
DefaultHistogram,
Expand All @@ -50,6 +49,7 @@
_ProxyObservableUpDownCounter,
_ProxyUpDownCounter,
)
from opentelemetry.environment_variables import OTEL_PYTHON_METER_PROVIDER
from opentelemetry.util._once import Once
from opentelemetry.util._providers import _load_provider

Expand Down Expand Up @@ -147,7 +147,7 @@ def create_observable_counter(
An observable counter observes a monotonically increasing count by
calling a provided callback which returns multiple
:class:`~opentelemetry.metrics.measurement.Measurement`.
:class:`~opentelemetry._metrics.measurement.Measurement`.
For example, an observable counter could be used to report system CPU
time periodically. Here is a basic implementation::
Expand Down Expand Up @@ -187,7 +187,7 @@ def cpu_time_callback() -> Iterable[Measurement]:
Alternatively, you can pass a generator directly instead of a callback,
which should return iterables of
:class:`~opentelemetry.metrics.measurement.Measurement`::
:class:`~opentelemetry._metrics.measurement.Measurement`::
def cpu_time_callback(states_to_include: set[str]) -> Iterable[Iterable[Measurement]]:
while True:
Expand All @@ -214,9 +214,9 @@ def cpu_time_callback(states_to_include: set[str]) -> Iterable[Iterable[Measurem
Args:
name: The name of the instrument to be created
callback: A callback that returns an iterable of
:class:`~opentelemetry.metrics.measurement.Measurement`.
:class:`~opentelemetry._metrics.measurement.Measurement`.
Alternatively, can be a generator that yields iterables of
:class:`~opentelemetry.metrics.measurement.Measurement`.
:class:`~opentelemetry._metrics.measurement.Measurement`.
unit: The unit for measurements this instrument reports. For
example, ``By`` for bytes. UCUM units are recommended.
description: A description for this instrument and what it measures.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
)

# pylint: disable=unused-import; needed for typing and sphinx
from opentelemetry import metrics
from opentelemetry.metrics.measurement import Measurement
from opentelemetry import _metrics as metrics
from opentelemetry._metrics.measurement import Measurement

_TInstrumentCallback = Callable[[], Iterable[Measurement]]
_TInstrumentCallbackGenerator = Generator[Iterable[Measurement], None, None]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from typing import Generator, Iterable
from unittest import TestCase

from opentelemetry.metrics import _DefaultMeter
from opentelemetry.metrics.measurement import Measurement
from opentelemetry._metrics import _DefaultMeter
from opentelemetry._metrics.measurement import Measurement

# FIXME Test that the instrument methods can be called concurrently safely.

Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-api/tests/metrics/test_instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from inspect import Signature, isabstract, signature
from unittest import TestCase

from opentelemetry.metrics import Meter, _DefaultMeter
from opentelemetry.metrics.instrument import (
from opentelemetry._metrics import Meter, _DefaultMeter
from opentelemetry._metrics.instrument import (
Counter,
DefaultCounter,
DefaultHistogram,
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/tests/metrics/test_measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from unittest import TestCase

from opentelemetry.metrics.measurement import Measurement
from opentelemetry._metrics.measurement import Measurement


class TestMeasurement(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/tests/metrics/test_meter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from unittest import TestCase

from opentelemetry.metrics import Meter
from opentelemetry._metrics import Meter

# FIXME Test that the meter methods can be called concurrently safely.

Expand Down
16 changes: 9 additions & 7 deletions opentelemetry-api/tests/metrics/test_meter_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@

from pytest import fixture

from opentelemetry import metrics
from opentelemetry.environment_variables import OTEL_PYTHON_METER_PROVIDER
from opentelemetry.metrics import (
from opentelemetry import _metrics as metrics
from opentelemetry._metrics import (
_DefaultMeter,
_DefaultMeterProvider,
_ProxyMeter,
_ProxyMeterProvider,
get_meter_provider,
set_meter_provider,
)
from opentelemetry.metrics.instrument import (
from opentelemetry._metrics.instrument import (
_ProxyCounter,
_ProxyHistogram,
_ProxyObservableCounter,
_ProxyObservableGauge,
_ProxyObservableUpDownCounter,
_ProxyUpDownCounter,
)
from opentelemetry.environment_variables import OTEL_PYTHON_METER_PROVIDER
from opentelemetry.test.globals_test import (
MetricsGlobalsTest,
reset_metrics_globals,
Expand Down Expand Up @@ -67,7 +67,9 @@ def test_set_meter_provider(reset_meter_provider):


def test_set_meter_provider_calls_proxy_provider(reset_meter_provider):
with patch("opentelemetry.metrics._PROXY_METER_PROVIDER") as mock_proxy_mp:
with patch(
"opentelemetry._metrics._PROXY_METER_PROVIDER"
) as mock_proxy_mp:
mock_real_mp = Mock()
set_meter_provider(mock_real_mp)
mock_proxy_mp.on_set_meter_provider.assert_called_once_with(
Expand All @@ -90,9 +92,9 @@ def test_get_meter_provider(reset_meter_provider):
"os.environ", {OTEL_PYTHON_METER_PROVIDER: "test_meter_provider"}
):

with patch("opentelemetry.metrics._load_provider", Mock()):
with patch("opentelemetry._metrics._load_provider", Mock()):
with patch(
"opentelemetry.metrics.cast",
"opentelemetry._metrics.cast",
Mock(**{"return_value": "test_meter_provider"}),
):
assert get_meter_provider() == "test_meter_provider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
from logging import getLogger
from typing import Optional

from opentelemetry.metrics import Meter as APIMeter
from opentelemetry.metrics import MeterProvider as APIMeterProvider
from opentelemetry.metrics import _DefaultMeter
from opentelemetry.metrics.instrument import (
from opentelemetry._metrics import Meter as APIMeter
from opentelemetry._metrics import MeterProvider as APIMeterProvider
from opentelemetry._metrics import _DefaultMeter
from opentelemetry._metrics.instrument import (
Counter,
Histogram,
ObservableCounter,
Expand Down Expand Up @@ -80,7 +80,7 @@ def create_observable_up_down_counter(


class MeterProvider(APIMeterProvider):
"""See `opentelemetry.metrics.MeterProvider`."""
"""See `opentelemetry._metrics.MeterProvider`."""

def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/tests/metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from unittest import TestCase
from unittest.mock import Mock

from opentelemetry.sdk.metrics import (
from opentelemetry.sdk._metrics import (
ConsoleMetricExporter,
MeterProvider,
SDKMetricReader,
Expand Down
2 changes: 1 addition & 1 deletion tests/util/src/opentelemetry/test/globals_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import unittest

from opentelemetry import metrics as metrics_api
from opentelemetry import _metrics as metrics_api
from opentelemetry import trace as trace_api
from opentelemetry.util._once import Once

Expand Down

0 comments on commit ef978ad

Please sign in to comment.