opentelemetry-sdk: drop NaN measurements at instrument level to prevent aggregation poisoning#5336
Open
RudraDudhat2509 wants to merge 2 commits into
Open
Conversation
Author
herin049
reviewed
Jun 19, 2026
| @@ -0,0 +1 @@ | |||
| `opentelemetry-sdk`: drop NaN measurements at the instrument level to prevent permanent aggregation poisoning | |||
Contributor
There was a problem hiding this comment.
Changelog fragment number should match the PR number
Author
There was a problem hiding this comment.
Recent commit addresses the same, thx for pointing it out !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
NaNmeasurements passed to metric instruments (e.g.counter.add(float("nan"))) were silently folded into running aggregations, permanently poisoning the sum, all subsequent exports emittednanwith no recovery pathif amount < 0guard onCounterandHistogramis bypassed byNaNbecause all IEEE 754 comparisons againstNaNreturnFalsemath.isnan()check at the instrument level (same layer as the existing negative-value guard) for all sync instruments (Counter,UpDownCounter,Histogram,Gauge) and in the async callback path, matching the approach taken in the Java SDK (open-telemetry/opentelemetry-java#5846, fixed in PR #5859)Closes #5330
What was tested
test_add_nantoTestCounterandTestUpDownCountertest_record_nantoTestHistogramtest_set_nantoTestGaugetest_nan_callback_value_is_droppedtoTestObservableGauge(verifies NaN from async callbacks is skipped, valid measurements still pass through)python -m pytest opentelemetry-sdk/tests/metrics/test_instrument.py)counter.add(1) → add(NaN) → add(5)now yieldssum = 6, notnan