Skip to content

Commit 450cce1

Browse files
Alex Botensrikanthccv
andauthored
[docs] adding more metrics documentation (#2574)
* [docs] adding more metrics documentation Adding docs around instruments and the methods to create them. I've also added an exclusion list for things that aren't really useful for users. * fix lint Co-authored-by: Srikanth Chekuri <[email protected]>
1 parent 37e9387 commit 450cce1

File tree

3 files changed

+70
-9
lines changed

3 files changed

+70
-9
lines changed

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
"undoc-members": True,
148148
"show-inheritance": True,
149149
"member-order": "bysource",
150+
"exclude-members": "_ProxyObservableUpDownCounter,_ProxyHistogram,_ProxyObservableGauge,_ProxyInstrument,_ProxyAsynchronousInstrument,_ProxyCounter,_ProxyUpDownCounter,_ProxyObservableCounter,_ProxyObservableGauge,_abc_impl",
150151
}
151152

152153
# -- Options for HTML output -------------------------------------------------

opentelemetry-api/src/opentelemetry/_metrics/__init__.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,33 @@ def schema_url(self):
136136

137137
@abstractmethod
138138
def create_counter(self, name, unit="", description="") -> Counter:
139-
pass
139+
"""Creates a `Counter` instrument
140+
141+
Args:
142+
name: The name of the instrument to be created
143+
unit: The unit for measurements this instrument reports. For
144+
example, ``By`` for bytes. UCUM units are recommended.
145+
description: A description for this instrument and what it measures.
146+
"""
140147

141148
@abstractmethod
142149
def create_up_down_counter(
143150
self, name, unit="", description=""
144151
) -> UpDownCounter:
145-
pass
152+
"""Creates an `UpDownCounter` instrument
153+
154+
Args:
155+
name: The name of the instrument to be created
156+
unit: The unit for measurements this instrument reports. For
157+
example, ``By`` for bytes. UCUM units are recommended.
158+
description: A description for this instrument and what it measures.
159+
"""
146160

147161
@abstractmethod
148162
def create_observable_counter(
149163
self, name, callback, unit="", description=""
150164
) -> ObservableCounter:
151-
"""Creates an observable counter instrument
165+
"""Creates an `ObservableCounter` instrument
152166
153167
An observable counter observes a monotonically increasing count by
154168
calling a provided callback which returns multiple
@@ -229,19 +243,48 @@ def cpu_time_callback(states_to_include: set[str]) -> Iterable[Iterable[Measurem
229243

230244
@abstractmethod
231245
def create_histogram(self, name, unit="", description="") -> Histogram:
232-
pass
246+
"""Creates a `Histogram` instrument
247+
248+
Args:
249+
name: The name of the instrument to be created
250+
unit: The unit for measurements this instrument reports. For
251+
example, ``By`` for bytes. UCUM units are recommended.
252+
description: A description for this instrument and what it measures.
253+
"""
233254

234255
@abstractmethod
235256
def create_observable_gauge(
236257
self, name, callback, unit="", description=""
237258
) -> ObservableGauge:
238-
pass
259+
"""Creates an `ObservableGauge` instrument
260+
261+
Args:
262+
name: The name of the instrument to be created
263+
callback: A callback that returns an iterable of
264+
:class:`~opentelemetry._metrics.measurement.Measurement`.
265+
Alternatively, can be a generator that yields iterables of
266+
:class:`~opentelemetry._metrics.measurement.Measurement`.
267+
unit: The unit for measurements this instrument reports. For
268+
example, ``By`` for bytes. UCUM units are recommended.
269+
description: A description for this instrument and what it measures.
270+
"""
239271

240272
@abstractmethod
241273
def create_observable_up_down_counter(
242274
self, name, callback, unit="", description=""
243275
) -> ObservableUpDownCounter:
244-
pass
276+
"""Creates an `ObservableUpDownCounter` instrument
277+
278+
Args:
279+
name: The name of the instrument to be created
280+
callback: A callback that returns an iterable of
281+
:class:`~opentelemetry._metrics.measurement.Measurement`.
282+
Alternatively, can be a generator that yields iterables of
283+
:class:`~opentelemetry._metrics.measurement.Measurement`.
284+
unit: The unit for measurements this instrument reports. For
285+
example, ``By`` for bytes. UCUM units are recommended.
286+
description: A description for this instrument and what it measures.
287+
"""
245288

246289

247290
class _ProxyMeter(Meter):

opentelemetry-api/src/opentelemetry/_metrics/instrument.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class _NonMonotonic(_Adding):
111111

112112

113113
class Counter(_Monotonic, Synchronous):
114+
"""A Counter is a synchronous `Instrument` which supports non-negative increments."""
115+
114116
@abstractmethod
115117
def add(self, amount, attributes=None):
116118
# FIXME check that the amount is non negative
@@ -135,6 +137,8 @@ def _create_real_instrument(self, meter: "metrics.Meter") -> Counter:
135137

136138

137139
class UpDownCounter(_NonMonotonic, Synchronous):
140+
"""An UpDownCounter is a synchronous `Instrument` which supports increments and decrements."""
141+
138142
@abstractmethod
139143
def add(self, amount, attributes=None):
140144
pass
@@ -160,7 +164,9 @@ def _create_real_instrument(self, meter: "metrics.Meter") -> UpDownCounter:
160164

161165

162166
class ObservableCounter(_Monotonic, Asynchronous):
163-
pass
167+
"""An ObservableCounter is an asynchronous `Instrument` which reports monotonically
168+
increasing value(s) when the instrument is being observed.
169+
"""
164170

165171

166172
class DefaultObservableCounter(ObservableCounter):
@@ -180,7 +186,10 @@ def _create_real_instrument(
180186

181187

182188
class ObservableUpDownCounter(_NonMonotonic, Asynchronous):
183-
pass
189+
"""An ObservableUpDownCounter is an asynchronous `Instrument` which reports additive value(s) (e.g.
190+
the process heap size - it makes sense to report the heap size from multiple processes and sum them
191+
up, so we get the total heap usage) when the instrument is being observed.
192+
"""
184193

185194

186195
class DefaultObservableUpDownCounter(ObservableUpDownCounter):
@@ -201,6 +210,11 @@ def _create_real_instrument(
201210

202211

203212
class Histogram(_Grouping, Synchronous):
213+
"""Histogram is a synchronous `Instrument` which can be used to report arbitrary values
214+
that are likely to be statistically meaningful. It is intended for statistics such as
215+
histograms, summaries, and percentile.
216+
"""
217+
204218
@abstractmethod
205219
def record(self, amount, attributes=None):
206220
pass
@@ -226,7 +240,10 @@ def _create_real_instrument(self, meter: "metrics.Meter") -> Histogram:
226240

227241

228242
class ObservableGauge(_Grouping, Asynchronous):
229-
pass
243+
"""Asynchronous Gauge is an asynchronous `Instrument` which reports non-additive value(s) (e.g.
244+
the room temperature - it makes no sense to report the temperature value from multiple rooms
245+
and sum them up) when the instrument is being observed.
246+
"""
230247

231248

232249
class DefaultObservableGauge(ObservableGauge):

0 commit comments

Comments
 (0)