Skip to content

Commit 26c7166

Browse files
cluster2600xrmxclaude
authored
api: add docstrings to core metrics instrument abstract methods (open-telemetry#4923)
* api: add docstrings to core metrics instrument abstract methods Add missing docstrings to the abstract measurement methods on the four core synchronous metric instruments: - Counter.add – records a non-negative increment - UpDownCounter.add – records a positive or negative delta - Histogram.record – records an arbitrary statistical measurement - Gauge.set – records the current (non-additive) value Each docstring explains the intent of the method, any constraints on the parameter, and documents all three parameters (amount, attributes, context) using the existing Google-style format already present in the codebase. These methods are the primary interaction surface for developers using the OpenTelemetry Metrics API; having no docstring on the abstract definition makes generated API docs and IDE tooltips silent. * Apply suggestion from @xrmx * api: remove CHANGELOG entry per reviewer request Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ci: retrigger CI checks --------- Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c17ba89 commit 26c7166

File tree

1 file changed

+46
-4
lines changed
  • opentelemetry-api/src/opentelemetry/metrics/_internal

1 file changed

+46
-4
lines changed

opentelemetry-api/src/opentelemetry/metrics/_internal/instrument.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,14 @@ def add(
183183
attributes: Optional[Attributes] = None,
184184
context: Optional[Context] = None,
185185
) -> None:
186-
pass
186+
"""Records an increment to the counter.
187+
188+
Args:
189+
amount: The amount to increment the counter by. Must be non-negative.
190+
attributes: Optional set of attributes to associate with the measurement.
191+
context: Optional context to associate with the measurement. If not
192+
provided, the current context is used.
193+
"""
187194

188195

189196
class NoOpCounter(Counter):
@@ -234,7 +241,18 @@ def add(
234241
attributes: Optional[Attributes] = None,
235242
context: Optional[Context] = None,
236243
) -> None:
237-
pass
244+
"""Records an increment or decrement to the counter.
245+
246+
Unlike `Counter`, the ``amount`` may be negative, allowing the
247+
instrument to track values that go up and down (e.g. number of
248+
active requests, queue depth).
249+
250+
Args:
251+
amount: The amount to add to the counter. May be positive or negative.
252+
attributes: Optional set of attributes to associate with the measurement.
253+
context: Optional context to associate with the measurement. If not
254+
provided, the current context is used.
255+
"""
238256

239257

240258
class NoOpUpDownCounter(UpDownCounter):
@@ -376,7 +394,20 @@ def record(
376394
attributes: Optional[Attributes] = None,
377395
context: Optional[Context] = None,
378396
) -> None:
379-
pass
397+
"""Records a measurement.
398+
399+
Used to report measurements that are likely to be statistically
400+
meaningful, such as request durations, payload sizes, or any value
401+
for which a distribution (e.g. percentiles) is useful.
402+
403+
Args:
404+
amount: The measurement to record. Should be non-negative in most
405+
cases; negative values are only meaningful when the histogram
406+
is used to track signed deltas.
407+
attributes: Optional set of attributes to associate with the measurement.
408+
context: Optional context to associate with the measurement. If not
409+
provided, the current context is used.
410+
"""
380411

381412

382413
class NoOpHistogram(Histogram):
@@ -486,7 +517,18 @@ def set(
486517
attributes: Optional[Attributes] = None,
487518
context: Optional[Context] = None,
488519
) -> None:
489-
pass
520+
"""Records the current value of the gauge.
521+
522+
The gauge reports the last recorded value when observed. It is
523+
intended for non-additive measurements where only the current
524+
value matters (e.g. CPU utilisation percentage, room temperature).
525+
526+
Args:
527+
amount: The current value to record.
528+
attributes: Optional set of attributes to associate with the measurement.
529+
context: Optional context to associate with the measurement. If not
530+
provided, the current context is used.
531+
"""
490532

491533

492534
class NoOpGauge(Gauge):

0 commit comments

Comments
 (0)