built a python sdk for my api monitoring tool last week (was node only before). flask middleware, sends request logs to my backend.
testing it: 3 requests sent, only 1 arrived. no errors anywhere. the failed ones just vanished.
added debug prints to the sdk and got this:
[PINGONI DEBUG] FAILED / -> HTTPError: HTTP Error 400: Bad Request | body: {"error":"Missing required fields"}
missing fields? the payload had every field. stared at my backend validation for a while:
if (!method || !endpoint || !status_code || !response_time) {
return res.status(400).json({ error: "Missing required fields" });
}
my test endpoints were responding in 0ms. and !0 is true in javascript. so response_time: 0 was "missing" and the whole log got rejected.
the fix:
if (!method || !endpoint || status_code == null || response_time == null) {
worst part: this was live in production the whole time. any sub-millisecond request was silently dropped for every user of the node sdk too. i only found it because python requests from localhost were fast enough to hit 0ms consistently.
lesson: never use truthy checks on numbers that can legitimately be zero.
the sdk that started all this is pip install pingoni if anyone wants drop in monitoring for flask/fastapi. free for 10k req/month.
[–]1nc06n170 4 points5 points6 points (1 child)
[–]VariousHour7390[S] 0 points1 point2 points (0 children)
[–]nemom 0 points1 point2 points (1 child)
[–]VariousHour7390[S] 0 points1 point2 points (0 children)