Repository navigation
fix: Drop Track calls with a NaN or infinite metric value - #664
Open
pcbeingused33 wants to merge 1 commit into
Open
pcbeingused33 wants to merge 1 commit into
pcbeingused33 wants to merge 1 commit into
Conversation
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>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trackwith a NaN or infinitemetric_valueputs 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.cppemplacesmetricValueas is). JSON has no representation for NaN or Infinity, so whatboost::jsonwrites 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::TrackInternalnow log a warning naming the event and return without recording it. On the server this happens after the context check and before theafterTrackhooks, 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
mainand pass with this change; the rest ofHooksTestandClientTestpass (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
Tracknow reject non-finite metric values (NaN, +Inf, −Inf) before events are enqueued or hooks run.In
ClientImpl::TrackInternal, when ametric_valueis present, the SDK checksstd::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 beforeafterTrackhooks, matching the Go SDK behavior. Finite metrics are unchanged.Tests: client-side
TrackWithNonFiniteMetricValueLogsWarning(custom log backend counts three warnings); server-sideTrackWithNonFiniteMetricValueIsNotRecorded(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.