15
15
# pylint: disable=too-many-ancestors
16
16
# type: ignore
17
17
18
- # FIXME enhance the documentation of this module
19
18
"""
20
- This module provides abstract and concrete (but noop) classes that can be used
21
- to generate metrics.
19
+ The OpenTelemetry metrics API describes the classes used to generate
20
+ metrics.
21
+
22
+ The :class:`.MeterProvider` provides users access to the :class:`.Meter` which in
23
+ turn is used to create :class:`.Instrument` objects. The :class:`.Instrument` objects are
24
+ used to record measurements.
25
+
26
+ This module provides abstract (i.e. unimplemented) classes required for
27
+ metrics, and a concrete no-op implementation :class:`.NoOpMeter` that allows applications
28
+ to use the API package alone without a supporting implementation.
29
+
30
+ To get a meter, you need to provide the package name from which you are
31
+ calling the meter APIs to OpenTelemetry by calling `MeterProvider.get_meter`
32
+ with the calling instrumentation name and the version of your package.
33
+
34
+ The following code shows how to obtain a meter using the global :class:`.MeterProvider`::
35
+
36
+ from opentelemetry._metrics import get_meter
37
+
38
+ meter = get_meter("example-meter")
39
+ counter = meter.create_counter("example-counter")
40
+
41
+ .. versionadded:: 1.10.0
22
42
"""
23
43
24
44
59
79
60
80
61
81
class MeterProvider (ABC ):
82
+ """
83
+ MeterProvider is the entry point of the API. It provides access to `Meter` instances.
84
+ """
85
+
62
86
@abstractmethod
63
87
def get_meter (
64
88
self ,
65
- name ,
66
- version = None ,
67
- schema_url = None ,
89
+ name : str ,
90
+ version : str = None ,
91
+ schema_url : str = None ,
68
92
) -> "Meter" :
69
- pass
93
+ """Returns a `Meter` for use by the given instrumentation library.
94
+
95
+ For any two calls it is undefined whether the same or different
96
+ `Meter` instances are returned, even for different library names.
97
+
98
+ This function may return different `Meter` types (e.g. a no-op meter
99
+ vs. a functional meter).
100
+
101
+ Args:
102
+ name: The name of the instrumenting module.
103
+ ``__name__`` may not be used as this can result in
104
+ different meter names if the meters are in different files.
105
+ It is better to use a fixed string that can be imported where
106
+ needed and used consistently as the name of the meter.
107
+
108
+ This should *not* be the name of the module that is
109
+ instrumented but the name of the module doing the instrumentation.
110
+ E.g., instead of ``"requests"``, use
111
+ ``"opentelemetry.instrumentation.requests"``.
112
+
113
+ version: Optional. The version string of the
114
+ instrumenting library. Usually this should be the same as
115
+ ``pkg_resources.get_distribution(instrumenting_library_name).version``.
116
+
117
+ schema_url: Optional. Specifies the Schema URL of the emitted telemetry.
118
+ """
70
119
71
120
72
121
class NoOpMeterProvider (MeterProvider ):
@@ -113,7 +162,13 @@ def on_set_meter_provider(self, meter_provider: MeterProvider) -> None:
113
162
114
163
115
164
class Meter (ABC ):
116
- def __init__ (self , name , version = None , schema_url = None ):
165
+ """Handles instrument creation.
166
+
167
+ This class provides methods for creating instruments which are then
168
+ used to produce measurements.
169
+ """
170
+
171
+ def __init__ (self , name : str , version : str = None , schema_url : str = None ):
117
172
super ().__init__ ()
118
173
self ._name = name
119
174
self ._version = version
@@ -123,14 +178,23 @@ def __init__(self, name, version=None, schema_url=None):
123
178
124
179
@property
125
180
def name (self ):
181
+ """
182
+ The name of the instrumenting module.
183
+ """
126
184
return self ._name
127
185
128
186
@property
129
187
def version (self ):
188
+ """
189
+ The version string of the instrumenting library.
190
+ """
130
191
return self ._version
131
192
132
193
@property
133
194
def schema_url (self ):
195
+ """
196
+ Specifies the Schema URL of the emitted telemetry
197
+ """
134
198
return self ._schema_url
135
199
136
200
def _check_instrument_id (
@@ -156,7 +220,9 @@ def _check_instrument_id(
156
220
return result
157
221
158
222
@abstractmethod
159
- def create_counter (self , name , unit = "" , description = "" ) -> Counter :
223
+ def create_counter (
224
+ self , name : str , unit : str = "" , description : str = ""
225
+ ) -> Counter :
160
226
"""Creates a `Counter` instrument
161
227
162
228
Args:
@@ -168,7 +234,7 @@ def create_counter(self, name, unit="", description="") -> Counter:
168
234
169
235
@abstractmethod
170
236
def create_up_down_counter (
171
- self , name , unit = "" , description = ""
237
+ self , name : str , unit : str = "" , description : str = ""
172
238
) -> UpDownCounter :
173
239
"""Creates an `UpDownCounter` instrument
174
240
0 commit comments