Skip to content

feat(otlp): Improved support for OTLP JSON metrics serialization (NaN,Infinity,-Infinity)#3496

Open
LorenzoTettamanti wants to merge 15 commits into
open-telemetry:mainfrom
LorenzoTettamanti:issue_3284
Open

feat(otlp): Improved support for OTLP JSON metrics serialization (NaN,Infinity,-Infinity)#3496
LorenzoTettamanti wants to merge 15 commits into
open-telemetry:mainfrom
LorenzoTettamanti:issue_3284

Conversation

@LorenzoTettamanti

@LorenzoTettamanti LorenzoTettamanti commented May 6, 2026

Copy link
Copy Markdown

Updates #3442

Changes

  • Added Serialize/Deserialization for NaN,Infinity,-Infinity to the following metrics fields:
Source Field Type
HistogramDataPoint sum, min, max Option<f64>
HistogramDataPoint explicit_bounds Vec<f64>
ExponentialHistogramDataPoint sum, min, max Option<f64>
ExponentialHistogramDataPoint zero_threshold f64
SummaryDataPoint sum f64
NumberDataPoint::Value AsDouble f64
Exemplar::Value AsDouble f64
AnyValue DoubleValue f64
  • Added regression tests covering NaN/Infinity serialization/deserialization for each affected field

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

LorenzoTettamanti and others added 7 commits May 3, 2026 13:55
…tion<f64> type. Added tests in json_serde.rs for HistogramDataPoint.sum,HistogramDataPoint.min,HistogramDataPoint.max
…etrics.v1.SummaryDataPoint.value,metrics.v1.Exemplar.value,metrics.v1.ExponentialHistogramDataPoint.zeroThreshold
…DataPoint.value,metrics.v1.Exemplar.value,metrics.v1.ExponentialHistogramDataPoint.zeroThreshold
…stogram NaN metrics test,Added gauge NaN metrics test
@linux-foundation-easycla

linux-foundation-easycla Bot commented May 6, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.9%. Comparing base (2571776) to head (6fc8fb2).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3496   +/-   ##
=====================================
  Coverage   82.9%   82.9%           
=====================================
  Files        130     130           
  Lines      27350   27350           
=====================================
  Hits       22675   22675           
  Misses      4675    4675           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LorenzoTettamanti LorenzoTettamanti changed the title Enhanced coverage for OTLP JSON metrics serde issues feat(otlp) :Enhanced coverage for OTLP JSON metrics serde issues May 15, 2026
@LorenzoTettamanti LorenzoTettamanti changed the title feat(otlp) :Enhanced coverage for OTLP JSON metrics serde issues feat(otlp): Enhanced coverage for OTLP JSON metrics serde issues May 15, 2026
@LorenzoTettamanti LorenzoTettamanti changed the title feat(otlp): Enhanced coverage for OTLP JSON metrics serde issues feat(otlp): Improved support for OTLP JSON metrics serialization (NaN,Infinity,-Infinity) May 26, 2026
@LorenzoTettamanti LorenzoTettamanti marked this pull request as ready for review May 26, 2026 08:01
@LorenzoTettamanti LorenzoTettamanti requested a review from a team as a code owner May 26, 2026 08:01
@lazureykis

Copy link
Copy Markdown

Hi @LorenzoTettamanti — while reading the Option<f64> path I hit what looks like a round-trip regression for histograms and wanted to check it with you.

HistogramDataPoint/ExponentialHistogramDataPoint sum/min/max are Option<f64> with no skip_serializing_if, so when they're None the output contains "min":null (etc.). On serialize that's fine — serialize_option_f64_special emits null for None, same as main. But deserialize_option_f64_special calls deserialize_any, and its OptionF64Visitor only implements visit_f64/visit_u64/visit_i64/visit_str — there's no visit_unit/visit_none. serde_json routes JSON null to visit_unit, whose default impl errors, so the value fails to parse.

The effect is that the crate can no longer deserialize its own serialized output whenever a histogram leaves min/max/sum unset (a common case — min/max are optional and sum is omitted for non-monotonic histograms). On main this round-trips because the default Option<f64> deserializer handles null → None.

Minimal repro (serialize a HistogramDataPoint with min/max/sum = None, then deserialize the result): https://github.com/lazureykis/opentelemetry-rust/blob/58640d270b674ee03d9808ef210c454c379cf0fc/opentelemetry-proto/tests/histogram_none_f64_roundtrip_evidence.rs

It serializes to {...,"sum":null,...,"min":null,"max":null} and then panics on deserialize:
Error("invalid type: null, expected a float or a string representing NaN, Infinity, or -Infinity", line: 1, column: 82). The same test passes on main.

Would it make sense to have the visitor accept null — e.g. add visit_unit/visit_none returning Ok(None) (using deserialize_option so visit_none is reached)? Adding skip_serializing_if = "Option::is_none" to those fields would also stop emitting null, though that's a separate, pre-existing point and wouldn't cover external input that sends explicit null. What do you think?

@LorenzoTettamanti

LorenzoTettamanti commented Jun 20, 2026

Copy link
Copy Markdown
Author

Hi @lazureykis , that's a great catch. I think that's a great idea to implement the visit_unit and visit_none in the OptionF64Visitor (using deserialize_option) so visit_none is reached for null values. Also adding skip_serializing_if = "Option::is_none" it's a great idea and would help to reduce the JSON

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants