Repository navigation
fix: drop only unserializable events instead of the whole batch - #514
pcbeingused33 wants to merge 1 commit into
Conversation
|
Thanks for the detailed write-up and the regression specs. The repro made this easy to evaluate. We discussed this as a team and have decided not to take this change. We do want to drop only the bad events instead of the whole payload. Doing that well needs a broader change to how the flush path builds the payload, and we would rather design that properly than add a second encoding pass. Re-encoding also has its own failure modes. For example, an event can pass the per-event check and still fail when the batch is encoded again, and then the whole batch is lost anyway. For now, we plan to keep the current behavior along with the We'll close this for now. Thanks again for raising it. |
Requirements
Related issues
No issue in this repository. Follow-up to #498, which covered a non-finite
metric_value; the same failure remains for eventdata.Describe the solution you've provided
One event with unserializable content (for example
trackdata containing a nestedFloat::NAN, or a string that is not valid UTF-8) discards the whole analytics batch.events_out.to_jsonraises inside the flush worker aftertrigger_flushhas already cleared the outbox, so the other events and the summary are lost.When serializing the batch fails, the flush worker now drops only the events that cannot be serialized, logs a warning for each, and sends the rest. Batches that serialize normally take the same path as before, so
datais not inspected on everytrackcall.Two specs in
spec/events_spec.rb(nested NaN and invalid UTF-8 indata) record a healthy event next to a bad one and check that only the healthy one is delivered. Both fail without the change and pass with it; RuboCop reports no offenses on the two changed files.Reproduction:
Describe alternatives you've considered
datainrecord_custom_event, as fix: Prevent a NaN or infinite metric value from discarding all events in a flush #498 does formetric_value: it would walk everytrackpayload on the caller's thread to catch a rare case.Additional context
AI assistance was used to prepare the patch and regression tests.
Note
Overview
Fixes analytics batch loss when one custom event has unserializable
data. Previously, a failedevents_out.to_jsonin the flush worker could drop the entire batch after the outbox was already cleared—even though other events were valid.On batch serialization failure, the flush path now runs
drop_unserializable_events, which keeps only events that serialize individually, logs a warning per dropped event, and sends the remaining payload. The happy path is unchanged (no per-trackvalidation).Tests add coverage for bad custom
data(nestedFloat::NANand invalid UTF-8) alongside a healthy event, asserting only the good event is delivered—complementing the existing non-finitemetric_valuehandling at record time.Reviewed by Cursor Bugbot for commit 18f4bf2. Bugbot is set up for automated code reviews on this repo. Configure here.