Monitoring server-side errors
medium 30 minCatch errors in one place, add the facts that explain them, group the same fault into one issue, count them as a share of all requests, and call a person only when users are hurt.
See it run
From an exception to a call: capture, add facts, group, count against a promise, and find what makes no noise.
Operations
The pipeline
A database timeout in the payment service, in seven steps.
Step 1 of 7
An error
One user cannot pay
DatabaseError: connection timeout after 30,000 ms, in payment.ts, line 45.
Step 1: An error
try: handle(request)except Exception as e: event = enrich(e, trace, route, release) counter.inc(status=503) answer(503, request_id) tracker.send_later(event) issue = issues[fingerprint(event)] if share(counter) > limit: page(owner)- Gives you
- Cause in minutes
- Costs
- One middleware
- Waiting for a letter
- most users just leave
Answer first, report after. And count everything, also what is not reported.
In the real world
The same monitoring server-side errors doing real jobs. Pick one and step through it.
The bank answers 200, with a refusal inside.
Step 1 of 3
All green
chart
errors: 0%
Looks fine
The shop counts status codes: 0% errors.
Step 1: All green
Common mistakes
The bugs interviewers watch for, with the fix beside each.
An empty catch
criticalThe failure is hidden for ever.
Wrongtry: charge(card)except Exception: passRightexcept CardError as e: errors.inc(kind="card") raiseIds in the fingerprint
majorEvery event becomes its own issue.
Wrongkey = (type(e), str(e), request_id)Rightkey = (type(e), own_frame(e))Alert on a count
majorBusy hours always alert, quiet ones never.
Wrongerrors > 50Righterrors / requests > 0.01 and errors > 20Details for the caller
criticalStack traces and messages help attackers and confuse users.
Wrongreturn str(e), tracebackRightreturn title, status, request_id
Interview tips
Do
- Trace id in each report.
- Own types of exceptions.
- Stable fingerprints.
- Alert on shares.
- Clear severities.
Do not
- Passwords or personal data in events.
- Swallow exceptions.
- Alert on each error.
- Messages that say nothing.
- Forget the context.
CATCH
- Capture.
- Add context and trace.
- Track in an error tracker.
- Cluster equal ones.
- Handle: alert and respond.
Numbers
- 99.9% in 30 days: 43.2 minutes.
- 99.5%: 216 minutes.
- 5xx ours, 4xx usually theirs.
- Count all, keep some.