Skip to content

Validate numeric amount on synchronous metric instruments - #5963

Open
Dotify71 wants to merge 3 commits into
open-telemetry:mainfrom
Dotify71:fix-instrument-amount-type-validation
Open

Dotify71 wants to merge 3 commits into
open-telemetry:mainfrom
Dotify71:fix-instrument-amount-type-validation

Conversation

@Dotify71

Copy link
Copy Markdown
Contributor

Fixes #5962

Description

In synchronous metric instruments (Counter.add, UpDownCounter.add, Histogram.record, and Gauge.set), non-finite values were checked via math.isfinite(amount).

Passing non-numeric types (such as str, None, list, dict, or custom objects) caused math.isfinite() to raise an uncaught TypeError: must be real number, not <type>, violating the OpenTelemetry Error Handling Specification. Additionally, because bool is a subclass of int in Python, passing boolean values silently passed math.isfinite() and recorded 1 or 0.

This PR validates that amount is a real finite number (isinstance(amount, (int, float)), excluding booleans and non-finite values). Non-numeric and non-finite values log a warning and are ignored without raising exceptions.

@Dotify71
Dotify71 requested a review from a team as a code owner November 24, 2026 17:34
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-11-25 18:56 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with the author? Comment /dashboard route:author to route it back.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Synchronous metric instruments crash on non-numeric amount with uncaught TypeError

1 participant