Lesson 1 · Unit 01
Logs
Levels, JSON lines, the request id that ties lines together, and what never to write.
What you practise
- Levels, structured logs as JSON, a request id that ties lines together, what never to log
Try a question from this lesson
Pick one
Two checkouts ran in the same second on one server. One of them failed. Which one?
14:02:07 INFO start checkout
14:02:07 INFO start checkout
14:02:07 INFO charge card
14:02:07 ERROR charge failed
14:02:07 INFO charge card
14:02:07 INFO order savedHint
Try to prove which "start checkout" the ERROR line belongs to.
Correct answer
These lines cannot tell you
Why
Nothing in a line says which request wrote it, and line order only shows how two requests interleaved. Guessing "the first one" is a coin flip. The fix is to stamp every line with an id that belongs to one request.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
A request id ties lines together
The service gives each incoming request a short random id and writes it on every line that request causes. Filter on the id and one request's story falls out of the noise, in order.
The id is passed along when the service calls another one, so the lines of both services can be joined.
14:02:07 INFO req=a41f start checkout
14:02:07 INFO req=b902 start checkout
14:02:07 INFO req=a41f charge card
14:02:07 ERROR req=a41f charge failed
14:02:07 INFO req=b902 charge card
14:02:07 INFO req=b902 order savedConcept
Structured logs: one JSON object per line
A sentence is easy to write and hard to query. A structured log line is a JSON object: the same facts, each in a named field. Now "count failed charges by status" is a lookup on status, not a guess about where a number sits in a sentence.
A few fields appear on every line: time, level, message and the request id.
{
"ts": "2026-03-01T14:02:07Z",
"level": "error",
"msg": "charge failed",
"request_id": "a41f",
"status": 502,
"attempt": 2
}9 more exercises in the app
- 2× type the answer
- 4× multiple choice
- 1× match the pairs
- 1× fill the blanks
- 1× true or false
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.