Skip to content

fix(telemetry): don't drop log and metric batches on NaN or Infinity - #3249

Open
pcbeingused333 wants to merge 1 commit into
getsentry:masterfrom
pcbeingused333:fix/non-finite-float-telemetry
Open

pcbeingused333 wants to merge 1 commit into
getsentry:masterfrom
pcbeingused333:fix/non-finite-float-telemetry

Conversation

@pcbeingused333

Copy link
Copy Markdown

A single Float::NAN or Float::INFINITY in a log attribute or parameter, or in a metric attribute or value, makes the SDK lose every log or metric buffered with it.

Sentry.metrics.count("checkout")
Sentry.metrics.gauge("cache.hit_ratio", 0.0 / 0.0)

Cause: JSON has no representation for non-finite floats, so JSON.generate raises GeneratorError when the batch envelope item is serialized, and the whole batch fails.

Fix:

  • Non-finite float attributes (including log parameters) are sent as strings ("NaN", "Infinity", "-Infinity").
  • Arrays and hashes that can't be serialized to JSON are sent as their inspect string; before, the raw object was kept and failed later.
  • A metric whose value is a non-finite float is dropped with a debug log message, since the value has to be a number.

Tests: new specs in metrics_spec.rb and log_event_spec.rb fail without the change and pass with it. RuboCop passes on the touched files.

This change was prepared with AI assistance.

JSON can't represent non-finite floats, so one of them in an attribute,
parameter or metric value made the whole envelope fail to serialize.
Send such attributes as strings and drop metrics with a non-finite value.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused333
pcbeingused333 requested review from a team and solnic as code owners November 29, 2026 00:07
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 3ac9c47.

Main concerns: data sent to Sentry, reach, host performance.

This label is a hint for reviewers, not an approval.

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

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant