DEV Community

Mobeen Ahmed
Mobeen Ahmed

Posted on

Logging provider failures without storing anything about the user

When something breaks on my video downloader, I need to know about it. But the site stores nothing about its visitors — no accounts, no cookies, no database — so the usual approach of logging a request with a user ID and an IP address was never an option. I had to build a failure log that tells me what went wrong without ever recording who it happened to.

The problem is real. The downloader on ramrom.io talks to several third-party providers, and providers fail in interesting ways: a timeout here, a changed response format there, the occasional "Service is busy" afternoon. When a visitor pastes a link and gets an honest error message, that is fine for them. But if I cannot see the failure, I cannot tell whether one platform is having a bad day or my code broke something.

So the resolve endpoint writes a line to a flat log file whenever a provider call fails. The line contains four things and nothing else: the time, which platform the link was for, which provider was called, and the error — a status code, a short message, or the raw shape of the unexpected response. That is the whole record.

What is deliberately missing matters more than what is there. No pasted URL, no IP address, no user agent string, no country, no session identifier. The pasted URL is the obvious one to leave out: a video link can identify a person, especially if it points to their own content. The IP address is the quieter risk — it feels like a normal thing to log, and most servers do it by default, but I do not need it to fix a provider error, so it does not get written down. Leaving it out costs me nothing and removes a whole class of problems.

The log file itself stays simple. It is a plain text file outside the web root, appended to with a file lock so concurrent requests do not garble each other, and it is capped by size: once it grows past a few megabytes I rotate it and keep only the last two files. A log that grows forever on shared hosting is a disk quota problem waiting to happen. Rotation also means old failures disappear on their own, which suits a log that was only ever meant for debugging the last few days.

There is a second benefit I did not expect. Because the log holds no personal data, I can open it without thinking twice about who might see it over my shoulder, and I can paste a snippet of it into a note or a support message to a provider without redacting anything. The day a provider changed its error JSON without telling anyone, I spotted it in the log within the hour, saw that only one platform was affected, and knew the fix belonged in my normalisation code rather than in the provider itself. That diagnosis took one look at the log. Without it, I would have been guessing.

A few rules keep the system honest. First, the code that writes the log never receives the raw request — it gets a small array built from the four allowed fields, so a future change cannot accidentally start logging URLs. Second, nothing in the log ever feeds back into the site: it is read by me, in a terminal, and nowhere else. Third, the error messages shown to visitors stay separate from the log. The visitor sees "the provider did not answer in time, please try again"; the log sees the timeout value and the endpoint that failed. One is for people, the other is for fixing things.

None of this is clever. A flat file, four fields, a size cap, and a habit of not logging what I do not need. But it is the difference between flying blind and knowing exactly which provider failed, when, and how — without ever writing down a single thing about the person who hit the button.

Top comments (0)