Skip to content

api: add docstrings to core metrics instrument abstract methods#4923

Open
cluster2600 wants to merge 5 commits intoopen-telemetry:mainfrom
cluster2600:fix/add-docstrings-to-metrics-instrument-methods
Open

api: add docstrings to core metrics instrument abstract methods#4923
cluster2600 wants to merge 5 commits intoopen-telemetry:mainfrom
cluster2600:fix/add-docstrings-to-metrics-instrument-methods

Conversation

@cluster2600
Copy link
Contributor

Description

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 amount parameter, and documents all three parameters (amount, attributes, context) using the existing Google-style format already present in the codebase (e.g. CallbackOptions, Observation).

These methods are the primary interaction surface for developers using the OpenTelemetry Metrics API; without docstrings on the abstract definitions, generated API docs and IDE tooltips are silent when hovering over the most commonly called methods.

Changes

  • opentelemetry-api/src/opentelemetry/metrics/_internal/instrument.py: Added docstrings to Counter.add, UpDownCounter.add, Histogram.record, and Gauge.set
  • CHANGELOG.md: Added entry under Unreleased

Type of change

  • This change requires a documentation update

How Has This Been Tested?

Documentation-only change; no functional code was altered.
Verified that the added docstrings follow the existing Google-style format used in CallbackOptions and Observation.

Does This PR Require a Contrib Repo Change?

  • No.

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.
@cluster2600 cluster2600 requested a review from a team as a code owner February 19, 2026 09:56
Copy link
Contributor

@tammy-baylis-swi tammy-baylis-swi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tammy-baylis-swi tammy-baylis-swi added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Feb 24, 2026
@cluster2600
Copy link
Contributor Author

The only failing check (contrib_0 / instrumentation-aio-pika-1) is unrelated to this PR — it's a uv pip install failure trying to resolve a git commit SHA (08e1f36...) that isn't accessible:

fatal: ambiguous argument '08e1f364d612c4dda0b0ef4fbbd0e908697d12b4^0':
unknown revision or path not in the working tree.

This is a CI infrastructure issue with the contrib test setup, not a regression from the docstring changes. All other checks pass. Could a maintainer merge when convenient? Thanks!

Copy link
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

We know there are some flakey test in the repo atm that can cause failures in unrelated PRs.

@tammy-baylis-swi tammy-baylis-swi moved this from Easy to review / merge / close to Approved PRs in @xrmx's Python PR digest Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip Changelog PRs that do not require a CHANGELOG.md entry

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

5 participants