Repository navigation
fix: Drop track events with a NaN or infinite metric value - #599
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Requirements
async_*siblings (or N/A)Related issues
No issue in this repository. Same fix as launchdarkly/go-server-sdk#520 and launchdarkly/ruby-server-sdk#498.
Describe the solution you've provided
track()with aNaNor infinitemetric_valueputs the value straight into the custom event. The event processor serializes the whole batch withjson.dumps, which by default writes the non-standard tokensNaN,Infinityand-Infinity, so the request body for that flush is not valid JSON and the other events in it are at risk too.LDClient.trackandAsyncLDClient.tracknow check for a non-finitefloatafter the existing context check. In that case they log a warning that names the event and do not record it. Other values behave as before, anddatais not inspected. The docstrings mention the new behavior.New tests cover
NaN,+Infinityand-Infinityon both clients. They fail without the change and pass with it. The client, async client and hook tests pass, andmypy,isortandpycodestyleare clean on the changed source files.Describe alternatives you've considered
metricValue: this would silently report a different measurement.allow_nan=Falsetojson.dumps: the whole batch would then fail to serialize.Additional context
This change was prepared with the assistance of an AI coding agent (Claude Code).
Note
Overview
track()onLDClientandAsyncLDClientnow rejectsfloat**metric_value**s that are NaN or ±Infinity: it logs a warning naming the event and does not enqueue the custom event.This matches other LaunchDarkly server SDKs and avoids event batches that
json.dumpswould emit with non-standard tokens, which can invalidate the flush payload and jeopardize co-batched events. Docstrings document the behavior; new parametrized tests cover sync and async clients.Reviewed by Cursor Bugbot for commit 6298882. Bugbot is set up for automated code reviews on this repo. Configure here.