Repository navigation
fix: isolate invalid custom analytics event data - #603
pcbeingused33 wants to merge 1 commit into
Conversation
|
Thanks for the detailed write-up and the sync and async tests. 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
async_*siblings (or N/A)Related issues
No issue in this repository. Follow-up to #599, which rejects non-finite
metric_valueintrack()but does not inspectdata.Describe the solution you've provided
Python's JSON encoder writes
NaN,Infinityand-Infinityby default. A non-finite number nested in thedatapassed totrack()is copied into the custom event as-is, and the event processor serializes the whole batch withjson.dumps, so that one value makes the request body for the entire flush invalid JSON. A value that cannot be encoded at all (for example adatetime) makesjson.dumpsraise, and the flush is dropped.The shared event formatter (
EventOutputFormatter, used by both the sync and async processors) now checks custom event data withjson.dumps(..., allow_nan=False). If that fails, it logs a warning naming the event and leaves that event out, so the rest of the batch is still sent. Dropping the event rather than its data matches what #599 does for non-finite metric values.New sync and async tests flush a batch containing one custom event with nested
NaN,+Infinityor-Infinityand one valid custom event over mock HTTP. They check that the payload encodes as strict JSON and still contains the valid event with its data. They fail without the change and pass with it; the event processor test suites pass.Describe alternatives you've considered
dataintrack(), as fix: Drop track events with a NaN or infinite metric value #599 does formetric_value: this would serialize the data on the caller's thread for every call, while the formatter already runs on the flush path and covers both clients in one place.allow_nan=Falseto the batchjson.dumps: the whole batch would then fail to serialize.Additional context
This change was prepared with the assistance of an AI coding agent.
Note
Overview
Custom events whose
datacannot be encoded as strict JSON (e.g. nestedNaN,Infinity, or non-JSON-serializable values) were previously included in the flush payload and could invalidate or drop the entire batch when the processor serializes it.EventOutputFormatter(shared by sync and async processors) now pre-validates customdatawithjson.dumps(..., allow_nan=False). Failed events are omitted with a warning keyed by event name;make_output_eventsskipsNoneresults so the rest of the batch still ships.New sync and async tests assert that a batch mixing one invalid and one valid custom event produces strict JSON and only delivers the valid event.
Reviewed by Cursor Bugbot for commit fba31a2. Bugbot is set up for automated code reviews on this repo. Configure here.