Standard library only · runs in your browser
At 14:03 checkout starts failing. The dashboard is red with checkout errors, and the obvious next step is to open checkout's code. The logs from three services say something else, if you read them in the right order.
Each log line looks like this:
2026-10-20T14:03:12Z level=ERROR svc=checkout req=r-1043 msg=payment_failed status=500
a timestamp, then key=value fields. The lines come from three services, merged as they arrived, so they are not in time order.
Write first_failure(lines). It returns the earliest ERROR by time:
{"service": "payments-db", "request_id": "r-1040", "time": "2026-10-20T14:03:01Z"}time is the timestamp string exactly as it appears in the line.level=ERROR or without svc.lines.None when there are no errors.first_failure(lines: list[str]) -> dict | None