Closed denschub closed 6 months ago
I added a second commit that updates all dependencies, because that's never a bad idea. We should set up dependabot or something similar eventually, but for now, this is good enough. The change to tsconfig.json
in that commit is from this change in prettier
. If you prefer I adjust auto-formatting in a third commit (or extract the update-commits into a follow-up PR), let me know.
This PR adds logging. There are three main components:
1I added
winston
, which appears to be the de-facto standard logging library for a lot of cases to emit JSONL logs for everything. I'm personally not a huge fan of JSONL logs, but the GCP Log Explorer can parse that and offer filters. It's also what the nginx/openresty container emit, so this matches the existing setup. A benefit of this is that we can use the filter features int the Log explorer more effectively.Using
morgan
, a project maintained by the expressjs team, the server now emits a log line for every successful request (ifLOG_LEVEL >= info
). There is a bit of boilerplate code which doesn't look amazing, but the motivation here is to match the JSON payload sent by the reverse proxy, so we can use the same filters. I hope this helps figuring out why heartbeat requests fail sometimes. An example log line looks like this:I added more verbose logging in the
handleUserReports
function. If emitted (LOG_LEVEL >= verbose
), we receive a more detailed step-by-step logging output during the request, which hopefully helps us narrow down why the requests are so slow. An example of how this looks:I thought about adding a request-uuid so we can correlate the log entries with each other. That'd be easy to add, but it adds more boilerplate code, and the app isn't high-traffic enough for that to be a requirement, I think.
The default
LOG_LEVEL
isverbose
, so we don't need to change any deployment settings to get what we want.r? @moztcampbell