Skip to content

Commit

Permalink
Make metrics public
Browse files Browse the repository at this point in the history
Fixes #2682
  • Loading branch information
ocelotl committed May 13, 2022
1 parent 91211b3 commit 96f1f58
Show file tree
Hide file tree
Showing 55 changed files with 253 additions and 276 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.11.1-0.30b1...HEAD)

- Make metrics components public
([#2684](https://github.com/open-telemetry/opentelemetry-python/pull/2684))
- Update to semantic conventions v1.11.0
([#2669](https://github.com/open-telemetry/opentelemetry-python/pull/2669))
- Update opentelemetry-proto to v0.17.0
Expand Down
13 changes: 3 additions & 10 deletions docs/api/metrics.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
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``.
opentelemetry.metrics package
=============================

.. toctree::


Module contents
---------------

.. automodule:: opentelemetry._metrics
.. automodule:: opentelemetry.metrics
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@
("py:class", "ValueT"),
(
"py:class",
"opentelemetry.sdk._metrics._internal.instrument._Synchronous",
"opentelemetry.sdk.metrics._internal.instrument._Synchronous",
),
(
"py:class",
"opentelemetry.sdk._metrics._internal.instrument._Asynchronous",
"opentelemetry.sdk.metrics._internal.instrument._Asynchronous",
),
# Even if wrapt is added to intersphinx_mapping, sphinx keeps failing
# with "class reference target not found: ObjectProxy".
Expand Down
7 changes: 1 addition & 6 deletions docs/examples/metrics/README.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
OpenTelemetry Metrics SDK
=========================

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

Start the Collector locally to see data being exported. Write the following file:

.. code-block:: yaml
Expand Down Expand Up @@ -45,4 +40,4 @@ The resulting metrics will appear in the output from the collector and look simi

.. code-block:: sh
TODO
TODO
14 changes: 7 additions & 7 deletions docs/examples/metrics/example.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from typing import Iterable

from opentelemetry._metrics import (
from opentelemetry.exporter.otlp.proto.grpc._metric_exporter import (
OTLPMetricExporter,
)
from opentelemetry.metrics import (
Observation,
get_meter_provider,
set_meter_provider,
)
from opentelemetry._metrics._internal.instrument import CallbackOptions
from opentelemetry.exporter.otlp.proto.grpc._metric_exporter import (
OTLPMetricExporter,
)
from opentelemetry.sdk._metrics import MeterProvider
from opentelemetry.sdk._metrics.export import PeriodicExportingMetricReader
from opentelemetry.metrics._internal.instrument import CallbackOptions
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader

exporter = OTLPMetricExporter(insecure=True)
reader = PeriodicExportingMetricReader(exporter)
Expand Down
6 changes: 3 additions & 3 deletions docs/getting_started/metrics_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

from typing import Iterable

from opentelemetry._metrics import (
from opentelemetry.metrics import (
CallbackOptions,
Observation,
get_meter_provider,
set_meter_provider,
)
from opentelemetry.sdk._metrics import MeterProvider
from opentelemetry.sdk._metrics.export import (
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import (
ConsoleMetricExporter,
PeriodicExportingMetricReader,
)
Expand Down
6 changes: 3 additions & 3 deletions docs/sdk/metrics.export.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
opentelemetry.sdk._metrics.export
=================================
opentelemetry.sdk.metrics.export
================================

.. automodule:: opentelemetry.sdk._metrics.export
.. automodule:: opentelemetry.sdk.metrics.export
:members:
:undoc-members:
:show-inheritance:
11 changes: 2 additions & 9 deletions docs/sdk/metrics.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
opentelemetry.sdk._metrics package
opentelemetry.sdk.metrics package
==================================

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

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

Submodules
----------

Expand All @@ -16,7 +9,7 @@ Submodules
metrics.export
metrics.view

.. automodule:: opentelemetry.sdk._metrics
.. automodule:: opentelemetry.sdk.metrics
:members:
:undoc-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions docs/sdk/metrics.view.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
opentelemetry.sdk._metrics.view
===============================
opentelemetry.sdk.metrics.view
==============================

.. automodule:: opentelemetry.sdk._metrics.view
.. automodule:: opentelemetry.sdk.metrics.view
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_OTLP_METRICS_INSECURE,
)
from opentelemetry.sdk._metrics.export import (
from opentelemetry.sdk.metrics.export import (
Gauge,
Histogram,
Metric,
Sum,
)

from opentelemetry.sdk._metrics.export import (
from opentelemetry.sdk.metrics.export import (
MetricExporter,
MetricExportResult,
MetricsData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
from opentelemetry.proto.resource.v1.resource_pb2 import (
Resource as OTLPResource,
)
from opentelemetry.sdk._metrics.export import (
from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_OTLP_METRICS_INSECURE,
)
from opentelemetry.sdk.metrics.export import (
AggregationTemporality,
Histogram,
HistogramDataPoint,
Expand All @@ -50,9 +53,6 @@
ResourceMetrics,
ScopeMetrics,
)
from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_OTLP_METRICS_INSECURE,
)
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.util.instrumentation import (
InstrumentationScope as SDKInstrumentationScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from opentelemetry._metrics import get_meter_provider, set_meter_provider
from opentelemetry.exporter.prometheus import PrometheusMetricReader
from opentelemetry.sdk._metrics import MeterProvider
from opentelemetry.sdk.metrics import MeterProvider
# Start Prometheus client
start_http_server(port=8000, addr="localhost")
Expand Down Expand Up @@ -77,7 +77,7 @@
)
from prometheus_client.core import Metric as PrometheusMetric

from opentelemetry.sdk._metrics.export import (
from opentelemetry.sdk.metrics.export import (
Gauge,
Histogram,
HistogramDataPoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
PrometheusMetricReader,
_CustomCollector,
)
from opentelemetry.sdk._metrics.export import (
from opentelemetry.sdk.metrics.export import (
AggregationTemporality,
Histogram,
HistogramDataPoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
The following code shows how to obtain a meter using the global :class:`.MeterProvider`::
from opentelemetry._metrics import get_meter
from opentelemetry.metrics import get_meter
meter = get_meter("example-meter")
counter = meter.create_counter("example-counter")
.. versionadded:: 1.10.0
"""

from opentelemetry._metrics._internal import (
from opentelemetry.metrics._internal import (
Meter,
MeterProvider,
NoOpMeter,
Expand All @@ -47,7 +47,7 @@
get_meter_provider,
set_meter_provider,
)
from opentelemetry._metrics._internal.instrument import (
from opentelemetry.metrics._internal.instrument import (
Asynchronous,
CallbackOptions,
CallbackT,
Expand All @@ -66,7 +66,7 @@
Synchronous,
UpDownCounter,
)
from opentelemetry._metrics._internal.observation import Observation
from opentelemetry.metrics._internal.observation import Observation

for obj in [
Counter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
The following code shows how to obtain a meter using the global :class:`.MeterProvider`::
from opentelemetry._metrics import get_meter
from opentelemetry.metrics import get_meter
meter = get_meter("example-meter")
counter = meter.create_counter("example-counter")
Expand All @@ -47,7 +47,10 @@
from threading import Lock
from typing import List, Optional, Sequence, Set, Tuple, Union, cast

from opentelemetry._metrics._internal.instrument import (
from opentelemetry.environment_variables import (
_OTEL_PYTHON_METER_PROVIDER as OTEL_PYTHON_METER_PROVIDER,
)
from opentelemetry.metrics._internal.instrument import (
CallbackT,
Counter,
Histogram,
Expand All @@ -68,9 +71,6 @@
_ProxyObservableUpDownCounter,
_ProxyUpDownCounter,
)
from opentelemetry.environment_variables import (
_OTEL_PYTHON_METER_PROVIDER as OTEL_PYTHON_METER_PROVIDER,
)
from opentelemetry.util._once import Once
from opentelemetry.util._providers import _load_provider

Expand Down Expand Up @@ -280,8 +280,8 @@ def create_observable_counter(
"""Creates an `ObservableCounter` instrument
An observable counter observes a monotonically increasing count by calling provided
callbacks which accept a :class:`~opentelemetry._metrics.CallbackOptions` and return
multiple :class:`~opentelemetry._metrics.Observation`.
callbacks which accept a :class:`~opentelemetry.metrics.CallbackOptions` and return
multiple :class:`~opentelemetry.metrics.Observation`.
For example, an observable counter could be used to report system CPU
time periodically. Here is a basic implementation::
Expand Down Expand Up @@ -320,7 +320,7 @@ def cpu_time_callback(options: CallbackOptions) -> Iterable[Observation]:
# ... other states
Alternatively, you can pass a sequence of generators directly instead of a sequence of
callbacks, which each should return iterables of :class:`~opentelemetry._metrics.Observation`::
callbacks, which each should return iterables of :class:`~opentelemetry.metrics.Observation`::
def cpu_time_callback(states_to_include: set[str]) -> Iterable[Iterable[Observation]]:
# accept options sent in from OpenTelemetry
Expand All @@ -347,7 +347,7 @@ def cpu_time_callback(states_to_include: set[str]) -> Iterable[Iterable[Observat
description="CPU time"
)
The :class:`~opentelemetry._metrics.CallbackOptions` contain a timeout which the
The :class:`~opentelemetry.metrics.CallbackOptions` contain a timeout which the
callback should respect. For example if the callback does asynchronous work, like
making HTTP requests, it should respect the timeout::
Expand All @@ -359,8 +359,8 @@ def scrape_http_callback(options: CallbackOptions) -> Iterable[Observation]:
Args:
name: The name of the instrument to be created
callbacks: A sequence of callbacks that return an iterable of
:class:`~opentelemetry._metrics.Observation`. Alternatively, can be a sequence of generators that each
yields iterables of :class:`~opentelemetry._metrics.Observation`.
:class:`~opentelemetry.metrics.Observation`. Alternatively, can be a sequence of generators that each
yields iterables of :class:`~opentelemetry.metrics.Observation`.
unit: The unit for observations this instrument reports. For
example, ``By`` for bytes. UCUM units are recommended.
description: A description for this instrument and what it measures.
Expand All @@ -373,7 +373,7 @@ def create_histogram(
unit: str = "",
description: str = "",
) -> Histogram:
"""Creates a :class:`~opentelemetry._metrics.Histogram` instrument
"""Creates a :class:`~opentelemetry.metrics.Histogram` instrument
Args:
name: The name of the instrument to be created
Expand All @@ -395,8 +395,8 @@ def create_observable_gauge(
Args:
name: The name of the instrument to be created
callbacks: A sequence of callbacks that return an iterable of
:class:`~opentelemetry._metrics.Observation`. Alternatively, can be a generator that yields iterables
of :class:`~opentelemetry._metrics.Observation`.
:class:`~opentelemetry.metrics.Observation`. Alternatively, can be a generator that yields iterables
of :class:`~opentelemetry.metrics.Observation`.
unit: The unit for observations this instrument reports. For
example, ``By`` for bytes. UCUM units are recommended.
description: A description for this instrument and what it measures.
Expand All @@ -415,8 +415,8 @@ def create_observable_up_down_counter(
Args:
name: The name of the instrument to be created
callbacks: A sequence of callbacks that return an iterable of
:class:`~opentelemetry._metrics.Observation`. Alternatively, can be a generator that yields iterables
of :class:`~opentelemetry._metrics.Observation`.
:class:`~opentelemetry.metrics.Observation`. Alternatively, can be a generator that yields iterables
of :class:`~opentelemetry.metrics.Observation`.
unit: The unit for observations this instrument reports. For
example, ``By`` for bytes. UCUM units are recommended.
description: A description for this instrument and what it measures.
Expand Down Expand Up @@ -725,7 +725,7 @@ def get_meter(
"""Returns a `Meter` for use by the given instrumentation library.
This function is a convenience wrapper for
`opentelemetry._metrics.MeterProvider.get_meter`.
`opentelemetry.metrics.MeterProvider.get_meter`.
If meter_provider is omitted the current configured one is used.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
)

# pylint: disable=unused-import; needed for typing and sphinx
from opentelemetry import _metrics as metrics
from opentelemetry._metrics._internal.observation import Observation
from opentelemetry import metrics
from opentelemetry.metrics._internal.observation import Observation
from opentelemetry.util.types import Attributes

_logger = getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/src/opentelemetry/util/_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pkg_resources import iter_entry_points

if TYPE_CHECKING:
from opentelemetry._metrics import MeterProvider
from opentelemetry.metrics import MeterProvider
from opentelemetry.trace import TracerProvider

Provider = TypeVar("Provider", "TracerProvider", "MeterProvider")
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/tests/metrics/test_instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from inspect import Signature, isabstract, signature
from unittest import TestCase

from opentelemetry._metrics import (
from opentelemetry.metrics import (
Counter,
Histogram,
Instrument,
Expand Down
Loading

0 comments on commit 96f1f58

Please sign in to comment.