The symptom and three explanations#
The example is fictional. A customer's payment, request r-1004, failed at 09:41 UTC. The payments-worker logs calling card processor before every charge, and an engineer searching the logs for r-1004 cannot find that line. Three explanations fit:
- The path was skipped. The request never reached the charge: a validation check, a feature flag or an early return sent it elsewhere.
- The line was filtered. The statement ran, but the logger's level, a sampling rule or a rate limit discarded the line.
- The line was lost. The statement ran and the line sat in a buffer, in the process or in a log shipper, that never reached storage, because the process was killed or the shipper dropped data under pressure.
The first explanation says the charge did not happen. The other two say it may have. That difference is why the question matters, and why a search of the same logs cannot answer it. Choose the observation where explanations disagree
What each explanation predicts#
| Observation | Path skipped | Line filtered | Line lost in a buffer |
|---|---|---|---|
| The expected line | absent | absent | absent |
| Other lines of the same request | present, showing the other branch | only those at or above the threshold | none from its last seconds |
| Lines of other requests at the same time | present | same level missing for them too | missing for the same seconds |
| The dependency's record of the call | none | present | present |
| How the process ended | normally | normally | killed, crashed or restarted near that time |
The fourth row is the one that settles whether the code path ran, because the card processor writes its record in another process that the worker's logging cannot affect. The second and third rows then tell filtering from loss: a level filter removes a severity everywhere, while a lost buffer removes a stretch of time.
The lab: three ways to lose one line#
The script handles six payment requests and logs with Python's logging module to app.log. The card processor's side of each charge goes to processor.log, written and flushed at once. Request r-1004 fails in each world for a different reason. In skipped, a lower amount limit rejects it before the charge. In level, the logger is set to WARNING. In crash, a MemoryHandler buffers records until an ERROR or until it holds 50, and the process exits with os._exit in the middle of r-1004, which skips cleanup handlers and buffer flushing as a killed process would. It needs Python 3.6 or later. MemoryHandler · os._exit
import logging, logging.handlers, os, sys
if len(sys.argv) < 2 or sys.argv[1] not in ("skipped", "level", "crash"):
sys.exit("usage: python3 lost.py skipped|level|crash")
world = sys.argv[1] # skipped | level | crash
log = logging.getLogger("payments")
to_file = logging.FileHandler("app.log", mode="w")
to_file.setFormatter(logging.Formatter("%(levelname)s %(message)s"))
if world == "crash": # buffer records; flush at ERROR or when 50 are held
log.addHandler(logging.handlers.MemoryHandler(50, logging.ERROR, to_file))
else:
log.addHandler(to_file)
log.setLevel(logging.WARNING if world == "level" else logging.INFO)
processor = open("processor.log", "w") # the dependency's own record of each call
LIMIT = 900 if world == "skipped" else 5000
def handle(req, amount):
log.info("%s start amount=%d", req, amount)
if amount > LIMIT:
log.warning("%s rejected: over limit", req)
return 422
log.info("%s calling card processor", req) # the line we expect to find
processor.write(f"{req} charge amount={amount}\n"); processor.flush()
if req == "r-1004" and world == "crash":
os._exit(137) # killed mid-request: no handler flush, no atexit
if amount > 900:
log.error("%s declined by processor", req)
return 502
log.info("%s done", req)
return 200
for i, amount in enumerate([120, 40, 310, 75, 1200, 60], start=1000):
handle(f"r-{i}", amount)
Save it as lost.py in an empty directory. Before running it, write down for each world whether processor.log will contain r-1004, and how many lines app.log will hold. Then run:
for w in skipped level crash; do
python3 lost.py "$w"; code=$?
echo "== $w: exit $code, app.log $(wc -l < app.log) lines, processor.log $(wc -l < processor.log) lines"
grep -H 'r-1004' app.log processor.log | sed 's/^/ /'
done
Python 3.11 printed:
== skipped: exit 0, app.log 17 lines, processor.log 5 lines
app.log:INFO r-1004 start amount=1200
app.log:WARNING r-1004 rejected: over limit
== level: exit 0, app.log 1 lines, processor.log 6 lines
app.log:ERROR r-1004 declined by processor
processor.log:r-1004 charge amount=1200
== crash: exit 137, app.log 0 lines, processor.log 5 lines
processor.log:r-1004 charge amount=1200
calling card processor is missing for r-1004 in all three worlds. Only the skipped world has no charge in processor.log, and it is the only world whose log shows what the request did instead. The level world kept one line in the whole file, the ERROR; every INFO line of every request is gone. The crash world's app.log is empty: the four earlier requests' lines were lost along with r-1004's, and the exit status is 137, the status a shell reports for a process killed by signal 9, which the lab imitates. bash exit status
The prediction fails if processor.log records a charge for r-1004 in the skipped world, or if the crash world keeps the earlier requests' lines. To vary it, change the MemoryHandler capacity from 50 to 3: the buffer then flushes during the earlier requests, and only r-1004's two records are lost, a gap at the end of the log for the request in flight.
Read it on a real system#
Search every service's logs for the request ID, not only the service you expected to log the line, and read the request's lines in order. The dependency's record, the card processor's dashboard or API log in this example, is the strongest single observation. A counter or span for the same step works too, if it left the process before the process died. Link the browser evidence to the server's logs
Check how the process ended. On Kubernetes, these commands only read. kubectl logs --previous returns the logs of the container's previous instance, and the pod's lastState shows an exit code and a reason such as OOMKilled. Kubernetes logging · Exceed a container's memory limit
kubectl get pod POD -n payments \
-o jsonpath='{range .status.containerStatuses[*]}{.name} {.restartCount} {.lastState.terminated}{"\n"}{end}'
kubectl logs POD -n payments -c worker --previous | tail -n 50
Check the logger's level in the revision that ran, not in the repository's current default. In Python, a logger processes a record only when the record's level is at or above the logger's effective level, which it inherits from its ancestors when it sets none; isEnabledFor() answers the question directly. Logger.isEnabledFor
Check the stages between the process and storage. On a systemd host, journald drops a service's messages beyond RateLimitBurst within RateLimitIntervalSec, 10,000 messages in 30 seconds by default and scaled by the journal's free disk space, and logs a message with the number dropped; read journald's own messages for that window. journald.conf
journalctl -u systemd-journald --since "2026-11-20 09:35" --until "2026-11-20 09:50" --utc
An OpenTelemetry Collector reports log records it failed to enqueue or export, and records its receivers refused, in its internal metrics. Collector internal telemetry
sum(rate(otelcol_exporter_enqueue_failed_log_records[5m]))
sum(rate(otelcol_exporter_send_failed_log_records[5m]))
sum(rate(otelcol_receiver_refused_log_records[5m]))
Depending on the Collector version and its Prometheus exporter settings, these names may carry a _total suffix.
Limits#
A counter in the same process dies with it. If the process was killed between the increment and the next scrape or export, the counter loses the same moment the logs lost, so prefer the dependency's record or a span that was exported before the crash.
Sampling by request removes a whole request. Log sampling that keeps or drops all lines of a request makes the request look as if it never arrived. Check the sampling configuration before concluding that the request skipped the service.
Buffers exist outside logging. A program that writes logs with print() to stdout in a container writes to a block-buffered stream, because stdout is line-buffered only when interactive, and a kill loses whatever the buffer held; python -u or PYTHONUNBUFFERED turns that buffering off. Python's StreamHandler writes to stderr by default, which is line-buffered since Python 3.9. sys.stdout buffering · PYTHONUNBUFFERED
The line can exist and stay hidden: indexed under another service name, rejected by a parser, or stamped with a time outside your search window. Widen the search to the raw stream before concluding it was never written. Log timestamps out of order
Questions#
How do I prove a code path did not run?
You cannot prove it from the absence of one log line. Find something the path would have produced elsewhere: a call the dependency recorded, a row it wrote, a span, or a counter that was exported. When the request's own later lines show it took another branch, that is direct evidence too.
Why are logs missing right before a container restart?
Records still in a buffer when the process is killed never reach storage. That can be a buffering handler, a block-buffered stdout or a shipper's queue. Python's cleanup handlers, including the one that flushes logging at exit, do not run when the process is killed by an unhandled signal or exits through os._exit(). atexit
Should I log at INFO in production to avoid this?
The level decides which lines exist, so a statement you rely on for incident work needs a level that production keeps. For a step that matters, such as a charge, a counter or span beside the log line gives a second record that does not depend on log levels or sampling.