Video in progress
Log storage costs have reached several thousand dollars a month. How do you cut the volume without losing the ability to debug?
First I measure which services and which log lines produce most of the volume; usually a few "noisy" spots account for 70-80%. Then I cut them by lowering the level, sampling, turning them into metrics, and tiering retention.
📖 Answer
Don't start by guessing. In Loki or Elasticsearch, group the logs by service and logger and look at the volume. Almost always the picture is the same: INFO access logs for health checks, a "received message" line for every Kafka message, one package left on debug, and a full stack trace on every retry.
Then the layers:
- Things you don't need at all: the access log of
/actuator/health, a "start"/"end" pair for a successful request. Remove them. One final line per request (with duration, status and the main IDs) is enough. - Turn them into metrics: if a "Processed message" line is used only for counting, it should be a counter. A metric is hundreds of times cheaper than a log.
- Sampling: sample 1-5% of the DEBUG/INFO details of successful requests, and keep 100% of errors. To keep the logs of one trace intact, it is good to tie the sampling decision to
traceId. - Repeated stack traces: a full stack trace not on every retry, only on the last attempt.
- Tiered retention: 7 days in "hot" storage that is fast to search, 90 days in cheap object storage, and a separate long-term place for audit.
One warning: don't start cutting with errors. During an incident the most useful thing is WARN/ERROR and context. After every change I recall the last three incidents and check: "could we have found the cause without these logs?"
Sign up to mark studied questions and save your progress.