Skip to content

fix: Drop Track calls with a NaN or infinite metric value - #664

Open
pcbeingused33 wants to merge 1 commit into
launchdarkly:mainfrom
pcbeingused33:fix/track-non-finite-metric
Open

pcbeingused33 wants to merge 1 commit into
launchdarkly:mainfrom
pcbeingused33:fix/track-non-finite-metric

Conversation

@pcbeingused33

@pcbeingused33 pcbeingused33 commented Nov 28, 2026 •

Copy link
Copy Markdown

Track with a NaN or infinite metric_value puts a non-finite number into the custom event. There is no linked issue; this is the C++ counterpart of launchdarkly/go-server-sdk#520 and launchdarkly/ruby-server-sdk#498.

Cause: neither SDK checks the value before it reaches the event serializer (json_events.cpp emplaces metricValue as is). JSON has no representation for NaN or Infinity, so what boost::json writes for them (depending on the version) is either unusable by the service or a different value from the one passed in, and it shares a payload with other events.

Fix: the server and client ClientImpl::TrackInternal now log a warning naming the event and return without recording it. On the server this happens after the context check and before the afterTrack hooks, as in the Go SDK. The C bindings go through the same path. Finite values are unchanged.

Tests:

  • HooksTest.TrackWithNonFiniteMetricValueIsNotRecorded (server): NaN, +Inf and -Inf do not reach the hooks.
  • ClientTest.TrackWithNonFiniteMetricValueLogsWarning (client): each of the three logs a warning, a finite value does not.

Both fail on main and pass with this change; the rest of HooksTest and ClientTest pass (GCC, Linux, Debian packages for Boost; other platforms not tried). The tests observe the hooks and the log, not the event payload.

This change was prepared with AI assistance (Claude Code).


Note

Overview
Both client-side and server-side Track now reject non-finite metric values (NaN, +Inf, −Inf) before events are enqueued or hooks run.

In ClientImpl::TrackInternal, when a metric_value is present, the SDK checks std::isfinite; if it fails, it logs a warning naming the event and returns without recording. On the server, this runs after the invalid-context guard and before afterTrack hooks, matching the Go SDK behavior. Finite metrics are unchanged.

Tests: client-side TrackWithNonFiniteMetricValueLogsWarning (custom log backend counts three warnings); server-side TrackWithNonFiniteMetricValueIsNotRecorded (recording hooks see no track calls for the three non-finite values).

Reviewed by Cursor Bugbot for commit 7b87ea5. Bugbot is set up for automated code reviews on this repo. Configure here.

A non-finite metric value is not valid JSON data for an event. Both SDKs now log a warning and skip the event.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused33
pcbeingused33 requested a review from a team as a code owner November 28, 2026 12:02

This branch has not been deployed

No deployments
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.

1 participant