Skip to content

fix(attributes): Handle special float values correctly - #8067

Merged
sentrivana merged 2 commits into
masterfrom
ivana/handle-special-floats-as-attributes
Oct 20, 2026
Merged

sentrivana merged 2 commits into
masterfrom
ivana/handle-special-floats-as-attributes

Conversation

@sentrivana

Copy link
Copy Markdown
Collaborator

Fixes #8066

@sentrivana
sentrivana marked this pull request as ready for review October 20, 2026 08:15
@sentrivana
sentrivana requested a review from a team as a code owner October 20, 2026 08:16
@sentrivana
sentrivana enabled auto-merge (squash) October 20, 2026 08:19
Comment thread sentry_sdk/utils.py
Comment on lines +2171 to +2173
if isinstance(val, float) and (math.isinf(val) or math.isnan(val)):
return str(val)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-finite float-array attributes still break envelope JSON serialization

Homogeneous float lists and tuples containing NaN or infinity pass through format_attribute unchanged. serialize_attribute then emits them as array values, but envelope payloads are encoded with json_dumps(allow_nan=False), which raises ValueError. Normalize non-finite elements in float arrays before serialization, or otherwise ensure the resulting payload is valid JSON.

Evidence
  • format_attribute handles non-finite values only in its scalar-float branch; its homogeneous list and tuple branches return float elements unchanged.
  • serialize_attribute emits homogeneous lists as array values, so a value such as [float("nan")] remains in the payload.
  • Batchers place these serialized attributes in JSON payloads; PayloadRef.get_bytes() encodes them with json_dumps, which sets allow_nan=False and raises ValueError for NaN or infinity.
Also found at 1 additional location
  • tests/test_attributes.py:228-234

Identified by Warden · code-review · D6L-C4X

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Results 📊

✅ 133717 passed | ⏭️ 7276 skipped | Total: 140993 | Pass Rate: 94.84% | Execution Time: 466m 14s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +51
Passed Tests 📈 +51
Failed Tests —
Skipped Tests —

All tests are passing successfully.

✅ Patch coverage is 100.00% (2 of 2 changed executable lines covered; target 80%).
Project statement coverage is 90.26% (unchanged from base (0f7acd5) to head (b4e39f0)).

Changed files with executable lines (1)
File Patch coverage Changed executable lines
sentry_sdk/utils.py 100.00% 2/2 covered
Coverage diff
@@            Coverage Diff             @@
##        master     #8067       +/-##
==========================================
  Coverage    90.26%    90.26%        —%
==========================================
  Files          202       202         —
  Tracked lines     26660     26662        +2
  Branches      9926      9928        +2
==========================================
+ Hits         24062     24065        +3
+ Misses        2598      2597        -1
+ Partials      1510      1509        -1

Generated by Coverage Action

@sentrivana
sentrivana merged commit 641517a into master Oct 20, 2026
463 of 468 checks passed
@sentrivana
sentrivana deleted the ivana/handle-special-floats-as-attributes branch October 20, 2026 09:01
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.

One NaN or inf value silently drops the whole batch of logs, spans or metrics

2 participants