1515# pylint: disable=too-many-ancestors
1616# type: ignore
1717
18- # FIXME enhance the documentation of this module
1918"""
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
2242"""
2343
2444
5979
6080
6181class MeterProvider (ABC ):
82+ """
83+ MeterProvider is the entry point of the API. It provides access to `Meter` instances.
84+ """
85+
6286 @abstractmethod
6387 def get_meter (
6488 self ,
65- name ,
66- version = None ,
67- schema_url = None ,
89+ name : str ,
90+ version : str = None ,
91+ schema_url : str = None ,
6892 ) -> "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+ """
70119
71120
72121class NoOpMeterProvider (MeterProvider ):
@@ -113,7 +162,13 @@ def on_set_meter_provider(self, meter_provider: MeterProvider) -> None:
113162
114163
115164class 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 ):
117172 super ().__init__ ()
118173 self ._name = name
119174 self ._version = version
@@ -123,14 +178,23 @@ def __init__(self, name, version=None, schema_url=None):
123178
124179 @property
125180 def name (self ):
181+ """
182+ The name of the instrumenting module.
183+ """
126184 return self ._name
127185
128186 @property
129187 def version (self ):
188+ """
189+ The version string of the instrumenting library.
190+ """
130191 return self ._version
131192
132193 @property
133194 def schema_url (self ):
195+ """
196+ Specifies the Schema URL of the emitted telemetry
197+ """
134198 return self ._schema_url
135199
136200 def _check_instrument_id (
@@ -156,7 +220,9 @@ def _check_instrument_id(
156220 return result
157221
158222 @abstractmethod
159- def create_counter (self , name , unit = "" , description = "" ) -> Counter :
223+ def create_counter (
224+ self , name : str , unit : str = "" , description : str = ""
225+ ) -> Counter :
160226 """Creates a `Counter` instrument
161227
162228 Args:
@@ -168,7 +234,7 @@ def create_counter(self, name, unit="", description="") -> Counter:
168234
169235 @abstractmethod
170236 def create_up_down_counter (
171- self , name , unit = "" , description = ""
237+ self , name : str , unit : str = "" , description : str = ""
172238 ) -> UpDownCounter :
173239 """Creates an `UpDownCounter` instrument
174240
0 commit comments