[pdata] Use spec-compliant string representation for NaN and Infinity#15138
Conversation
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
77b7eb3 to
1951f94
Compare
Merging this PR will improve performance by 27.66%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | BenchmarkTraceSizeSpanCount |
60 ns | 47 ns | +27.66% |
Comparing Vanshul97:fix/float64-nan-infinity-string (1951f94) with main (5f78c13)
Footnotes
-
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
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. |
Summary
Update
float64AsStringto return"NaN","Infinity", and"-Infinity"instead of"json: unsupported value: ..."for special float values.Fixes #14487
Problem
The current
Value.AsString()for double values containingNaN,+Inf, or-Infreturns strings like:The OpenTelemetry specification's suggested string representation for non-OTLP protocols specifies these should be
"NaN","Infinity", and"-Infinity".Fix
Updated
float64AsStringinpdata/pcommon/value.goto return spec-compliant strings:math.NaN()→"NaN"math.Inf(1)→"Infinity"math.Inf(-1)→"-Infinity"Test Plan
"bad float64"test case and addedNaNand-Infinitycasespdatatest suite passes with-race