4.5.22 · D1Software Engineering

Foundations — Logging and monitoring — structured logging, metrics, alerting

2,211 words10 min readBack to topic

This page assumes you have seen nothing. Before you can read the parent note on Logging and Monitoring, you must be fluent in a handful of small ideas and symbols. We build each one from a picture, in an order where every idea leans only on the ones before it.


0. What is a "service" and why is it a black box?

Figure — Logging and monitoring — structured logging, metrics, alerting

Look at the figure: the box on the left is the service. Requests fly in, responses fly out, but the inside is dark. The three arrows leaving the top — words, numbers, a bell — are exactly logging, metrics, and alerting. Keep this picture; every later symbol lives on one of those three arrows.


1. An "event" and a "field" (the atom of a log)


2. Cardinality (why some fields are "expensive")


3. Number line, axes, and a "time series"

Metrics are numbers over time, so you need the picture of a number laid out.

Figure — Logging and monitoring — structured logging, metrics, alerting

In the figure the pale-yellow line only ever climbs — that is a counter. The blue line goes up and down — that is a gauge. Same axes, different shapes. The parent note's whole "Metrics" pillar lives on this picture.


4. Slope = rate = "per second" (why the topic needs division)

The parent note turns a counter into a rate. To read that formula you need one idea: slope.

Figure — Logging and monitoring — structured logging, metrics, alerting

The figure marks the two chosen points, the rise (vertical), and the run (horizontal). The steepness of that dashed line is the rate. A flatter line means fewer requests per second; a vertical jump means a burst.


5. Fractions, percentages, and the symbol


6. Sorting, rank, and the ceiling symbol (for percentiles)

Percentiles are the subtlest tool in the parent note, so we build every symbol.

Figure — Logging and monitoring — structured logging, metrics, alerting

The figure lays 10 sorted latency samples along a line. The p95 mark falls at rank , so is the biggest sample. With only 10 samples the tail (the single worst value) is the percentile — the picture makes obvious why you need many samples before p99 means anything.


7. The average, and why the topic distrusts it


Prerequisite map

service is a black box

emit evidence over time

event and field

JSON structured record

cardinality

number line and axis

time series

counter vs gauge

slope equals rate

Structured Logging pillar

Metrics pillar

sort rank ceiling

percentiles

latency tail watching

fraction and percent

one minus SLO

error budget and Alerting

Once these foundations are solid, the three pillars slot in: fields and cardinality feed structured logging, slope and time series feed metrics, and percentiles plus the fraction feed alerting.


Where these ideas go next

  • The umbrella property "infer inside state from outside signals" is Observability.
  • Stitching one request across services with a shared ID is Distributed Tracing.
  • Targets and budgets are formalised in SLI SLO SLA.
  • The tail-vs-average maths deepens in Percentiles and Distributions.
  • Storing time series efficiently is the job of Time Series Databases.
  • Acting on a fired alert is Incident Response.
  • Not logging secrets is PII and Data Privacy.
  • Shedding excess load ties into Rate Limiting.

Equipment checklist

Cover the right side and answer each. If any stumps you, reread its section above.

What is a "service" and why can't you just pause it to inspect it?
A long-running program answering requests; pausing it in production breaks live users, so it must describe itself while running.
What is a field, and how does it differ from a plain sentence?
A labelled key: value fact; unlike a sentence, the label and data are separated so a machine can query them.
What does high cardinality mean and which pillar tolerates it?
Many possible distinct values; logging tolerates it, metrics do not.
On a time-vs-value graph, which shape is a counter and which is a gauge?
Counter only rises (or resets to 0); gauge goes up and down.
Write the slope of a counter between and and say what it means.
— the rate, events per second.
What does mean?
A change in time, .
What does mean — is it multiplication?
"The value of counter at time "; the parentheses are a lookup, not multiplication.
If , what fraction may fail and why ?
; the whole is 1, subtract the success part to get the allowed failure part.
Evaluate and , and why round up for percentiles?
and ; rounding up never leaves too few samples below, preserving the " at or below" guarantee.
Define the p95 in one sentence.
The value that 95% of samples are at or below.
Why does the topic distrust the average latency?
It hides rare slow outliers (the tail), so a bad experience for a few users becomes invisible.