Skip to content

Commit cbc1b03

Browse files
committed
Move Metrics API behind internal package
1 parent 2541bc2 commit cbc1b03

File tree

23 files changed

+263
-189
lines changed

23 files changed

+263
-189
lines changed

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

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

10-
## [1.11.1-0.30b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.11.1-0.30b1) - 2022-04-21
11-
10+
- Move Metrics API behind internal package
11+
([#2651](https://github.com/open-telemetry/opentelemetry-python/pull/2651))
1212

13+
## [1.11.1-0.30b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.11.1-0.30b1) - 2022-04-21
1314

1415
- Fix unhandled callback exceptions on async instruments
1516
([#2614](https://github.com/open-telemetry/opentelemetry-python/pull/2614))

docs/api/metrics.instrument.rst

-8
This file was deleted.

docs/api/metrics.observation.rst

-7
This file was deleted.

docs/api/metrics.rst

-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@ opentelemetry._metrics package
88

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

11-
Submodules
12-
----------
13-
1411
.. toctree::
1512

16-
metrics.instrument
17-
metrics.observation
1813

1914
Module contents
2015
---------------

docs/conf.py

+1-21
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@
9797
# https://github.com/sphinx-doc/sphinx/pull/3744
9898
nitpick_ignore = [
9999
("py:class", "ValueT"),
100-
("py:class", "MetricT"),
101-
("py:class", "InstrumentT"),
102-
("py:obj", "opentelemetry._metrics.instrument.InstrumentT"),
103100
# Even if wrapt is added to intersphinx_mapping, sphinx keeps failing
104101
# with "class reference target not found: ObjectProxy".
105102
("py:class", "ObjectProxy"),
@@ -142,24 +139,7 @@
142139
"examples/error_handler/error_handler_1",
143140
]
144141

145-
_exclude_members = [
146-
"_ProxyObservableUpDownCounter",
147-
"_ProxyHistogram",
148-
"_ProxyObservableGauge",
149-
"_ProxyInstrument",
150-
"_ProxyAsynchronousInstrument",
151-
"_ProxyCounter",
152-
"_ProxyUpDownCounter",
153-
"_ProxyObservableCounter",
154-
"_ProxyObservableGauge",
155-
"_abc_impl",
156-
"_Adding",
157-
"_Grouping",
158-
"_Monotonic",
159-
"_NonMonotonic",
160-
"Synchronous",
161-
"Asynchronous",
162-
]
142+
_exclude_members = ["_abc_impl"]
163143

164144
autodoc_default_options = {
165145
"members": True,

docs/examples/metrics/example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Iterable
22

33
from opentelemetry._metrics import get_meter_provider, set_meter_provider
4-
from opentelemetry._metrics.observation import Observation
4+
from opentelemetry._metrics import Observation
55
from opentelemetry.exporter.otlp.proto.grpc._metric_exporter import (
66
OTLPMetricExporter,
77
)

docs/getting_started/metrics_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from typing import Iterable
1919

2020
from opentelemetry._metrics import get_meter_provider, set_meter_provider
21-
from opentelemetry._metrics.observation import Observation
21+
from opentelemetry._metrics import Observation
2222
from opentelemetry.sdk._metrics import MeterProvider
2323
from opentelemetry.sdk._metrics.export import (
2424
ConsoleMetricExporter,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""
16+
The OpenTelemetry metrics API describes the classes used to generate
17+
metrics.
18+
19+
The :class:`.MeterProvider` provides users access to the :class:`.Meter` which in
20+
turn is used to create :class:`.Instrument` objects. The :class:`.Instrument` objects are
21+
used to record measurements.
22+
23+
This module provides abstract (i.e. unimplemented) classes required for
24+
metrics, and a concrete no-op implementation :class:`.NoOpMeter` that allows applications
25+
to use the API package alone without a supporting implementation.
26+
27+
To get a meter, you need to provide the package name from which you are
28+
calling the meter APIs to OpenTelemetry by calling `MeterProvider.get_meter`
29+
with the calling instrumentation name and the version of your package.
30+
31+
The following code shows how to obtain a meter using the global :class:`.MeterProvider`::
32+
33+
from opentelemetry._metrics import get_meter
34+
35+
meter = get_meter("example-meter")
36+
counter = meter.create_counter("example-counter")
37+
38+
.. versionadded:: 1.10.0
39+
"""
40+
41+
from opentelemetry._metrics._internal import (
42+
Meter,
43+
MeterProvider,
44+
NoOpMeter,
45+
NoOpMeterProvider,
46+
get_meter,
47+
get_meter_provider,
48+
set_meter_provider,
49+
)
50+
from opentelemetry._metrics._internal.instrument import (
51+
CallbackT,
52+
Counter,
53+
Histogram,
54+
NoOpCounter,
55+
NoOpHistogram,
56+
NoOpObservableCounter,
57+
Synchronous,
58+
Asynchronous,
59+
Instrument,
60+
NoOpObservableGauge,
61+
NoOpObservableUpDownCounter,
62+
NoOpUpDownCounter,
63+
ObservableCounter,
64+
ObservableGauge,
65+
ObservableUpDownCounter,
66+
UpDownCounter,
67+
)
68+
from opentelemetry._metrics._internal.observation import Observation
69+
70+
for obj in [
71+
Counter,
72+
Synchronous,
73+
Asynchronous,
74+
get_meter_provider,
75+
get_meter,
76+
Histogram,
77+
Meter,
78+
MeterProvider,
79+
Instrument,
80+
NoOpCounter,
81+
NoOpHistogram,
82+
NoOpMeter,
83+
NoOpMeterProvider,
84+
NoOpObservableCounter,
85+
NoOpObservableGauge,
86+
NoOpObservableUpDownCounter,
87+
NoOpUpDownCounter,
88+
ObservableCounter,
89+
ObservableGauge,
90+
ObservableUpDownCounter,
91+
Observation,
92+
set_meter_provider,
93+
UpDownCounter,
94+
]:
95+
obj.__module__ = "opentelemetry._metrics"
96+
97+
__all__ = [
98+
"MeterProvider",
99+
"NoOpMeterProvider",
100+
"Meter",
101+
"Counter",
102+
"NoOpCounter",
103+
"UpDownCounter",
104+
"NoOpUpDownCounter",
105+
"Histogram",
106+
"NoOpHistogram",
107+
"ObservableCounter",
108+
"NoOpObservableCounter",
109+
"ObservableUpDownCounter",
110+
"Instrument",
111+
"Synchronous",
112+
"Asynchronous",
113+
"NoOpObservableGauge",
114+
"ObservableGauge",
115+
"NoOpObservableUpDownCounter",
116+
"get_meter",
117+
"get_meter_provider",
118+
"set_meter_provider",
119+
"Observation",
120+
"CallbackT",
121+
"NoOpMeter",
122+
]

0 commit comments

Comments
 (0)