Four months of log rotation, 3 AM pages and one outage. These are the decisions we would keep if we rebuilt our logging setup from the start, without the marketing words.
1. Log in JSON, decide the format later
Our version of "structured logging" is simple: the application writes JSON lines to stdout with service, level, event, request_id and duration_ms. Nothing else. Every time we started deciding "which fields are interesting" inside the app, the format changed five times in a month. Keep the app dumb, do the filtering later.
2. Pick one id and pass it everywhere
import uuid request_id = request.headers.get("x-request-id") or str(uuid.uuid4()) Log it, return it in a response header, and put it in every outbound call. It is the single field that turns a 40-minute investigation into a 4-minute one.
3. Sample at the edge, not in the app
1% of successful requests, 100% of errors, 100% of slow requests. Doing this in the collector means the application never behaves differently under load because of instrumentation.
4. Alert on symptoms, not on lines
"Error rate above 2% for five minutes" is an alert. "Any log line with level=ERROR" is a notification nobody reads after week two. Two symptoms per service is usually enough to start.
5. Write down what a log is allowed to contain
No passwords, no tokens, no full request bodies, no email addresses unless necessary. Put that in the review checklist, because the person adding the log line is not thinking about compliance at 6 PM.
Where the field notes end up
After an incident the first page anyone opens is the short checklist from the previous one. More of mine, including the probes I run on Python services before a deploy, live in github.com/barasel200-bit/uvicorn-teardown-notes.
What we dropped
Most custom dashboards. Dashboards nobody opens during an incident are decoration; trace views and one good overview page do more work.
