AlgoViz

Monitoring server-side errors

medium 30 min

Catch 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

PaymenttimeoutMiddlewareError trackerPrometheusOn call

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

UsersShop0% errorsBank200, refused

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

    critical

    The failure is hidden for ever.

    Wrong
    try: charge(card)except Exception: pass
    Right
    except CardError as e:    errors.inc(kind="card")    raise
  • Ids in the fingerprint

    major

    Every event becomes its own issue.

    Wrong
    key = (type(e), str(e), request_id)
    Right
    key = (type(e), own_frame(e))
  • Alert on a count

    major

    Busy hours always alert, quiet ones never.

    Wrong
    errors > 50
    Right
    errors / requests > 0.01 and errors > 20
  • Details for the caller

    critical

    Stack traces and messages help attackers and confuse users.

    Wrong
    return str(e), traceback
    Right
    return 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.