Skip to content

[pdata] Use spec-compliant string representation for NaN and Infinity#15138

Merged
dmitryax merged 1 commit intoopen-telemetry:mainfrom
Vanshul97:fix/float64-nan-infinity-string
Apr 21, 2026
Merged

[pdata] Use spec-compliant string representation for NaN and Infinity#15138
dmitryax merged 1 commit intoopen-telemetry:mainfrom
Vanshul97:fix/float64-nan-infinity-string

Conversation

@Vanshul97
Copy link
Copy Markdown
Contributor

Summary

Update float64AsString to return "NaN", "Infinity", and "-Infinity" instead of "json: unsupported value: ..." for special float values.

Fixes #14487

Problem

The current Value.AsString() for double values containing NaN, +Inf, or -Inf returns strings like:

json: unsupported value: +Inf
json: unsupported value: NaN

The OpenTelemetry specification's suggested string representation for non-OTLP protocols specifies these should be "NaN", "Infinity", and "-Infinity".

Fix

Updated float64AsString in pdata/pcommon/value.go to return spec-compliant strings:

  • math.NaN()"NaN"
  • math.Inf(1)"Infinity"
  • math.Inf(-1)"-Infinity"

Test Plan

  • Updated existing "bad float64" test case and added NaN and -Infinity cases
  • Full pdata test suite passes with -race

@Vanshul97 Vanshul97 requested review from a team, bogdandrutu and dmitryax as code owners April 17, 2026 12:41
Comment thread .chloggen/fix-float64-nan-infinity-string.yaml
Update float64AsString to return "NaN", "Infinity", and "-Infinity"
instead of "json: unsupported value: ..." for special float values.
This aligns with the OpenTelemetry specification's suggested string
representation of complex attributes for non-OTLP protocols.

Fixes open-telemetry#14487
@Vanshul97 Vanshul97 force-pushed the fix/float64-nan-infinity-string branch from 77b7eb3 to 1951f94 Compare April 21, 2026 06:20
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 21, 2026

Merging this PR will improve performance by 27.66%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 6 untouched benchmarks
⏩ 76 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
BenchmarkTraceSizeSpanCount 60 ns 47 ns +27.66%

Comparing Vanshul97:fix/float64-nan-infinity-string (1951f94) with main (5f78c13)

Open in CodSpeed

Footnotes

  1. 76 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.31%. Comparing base (307e3ab) to head (1951f94).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15138      +/-   ##
==========================================
+ Coverage   91.24%   91.31%   +0.07%     
==========================================
  Files         699      699              
  Lines       44913    44944      +31     
==========================================
+ Hits        40979    41041      +62     
+ Misses       2786     2759      -27     
+ Partials     1148     1144       -4     

☔ View full report in Codecov by Sentry.
📢 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.

@dmitryax dmitryax added this pull request to the merge queue Apr 21, 2026
Merged via the queue into open-telemetry:main with commit 37559a8 Apr 21, 2026
66 checks passed
@otelbot
Copy link
Copy Markdown
Contributor

otelbot Bot commented Apr 21, 2026

Thank you for your contribution @Vanshul97! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

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.

Handling NaN, Infinity, -Infinity in string representation of complex attributes

4 participants