What we would change about structured logging

These are the lessons about structured logging that we would repeat to every new colleague in their first month, every one with a short reason. The services write millions of lines of logs a day, but most of it only matters during the rare minutes when something breaks.

The Lessons

  1. Emitting durations and the outcome as separate fields lets a single query rank the slowest routes without regex.

  2. Log levels only help when the team agrees on what each level means.

  3. Less chatty logs with fuller fields take less and answer more than a flood of unstructured lines which hold very little.

Here is a typical log call as it stands now, without the parts that just matter on our own machines:

logger.warning("report built", extra={
    "status_code": resp.status_code,
    "user_id": user.id,
    "duration_ms": timer.ms(),
})