CSE Roadmap

Core tier · about 3 hours · 8 parts

Part 4 of 8 · 2 min read

What to log

Put the whole story of a request into a single event.

UDS's main tip is to store all the data about one work unit in a single event. A work unit is usually one request, or one message taken off a queue. In code, this means handing a context object down the code path, adding facts as they become known, and writing the event once at the end.

The event should say: - who created the work and what it was for; - whether it succeeded or failed; - how long specific steps took; - for every network call made, the response status and the time taken.

It must also be sanitised, stripped of sensitive data such as user content that developers should not see. (Module 7 returns to this.)

Correlation id. One event per work unit reduces the need to join records but does not remove it. If service A calls service B, understanding why the call failed means joining A's event with B's. UDS says every event should carry the id of the request or message, so the two can be matched.

A made-up case. A user's order fails. The edge service event shows request id r-9001, status 502, total 3,100 ms, and a call to the payment service that took 3,000 ms and returned 504. Searching for r-9001 in the payment service's logs finds an event that says its own database call timed out after 2,900 ms. Two events and one id located the cause in minutes.

Correlation id

A correlation id (also called a request id) is a unique value created at the start of a request and copied into every event and call it causes, so that all related records can be found together.

Example: the edge assigns r-9001 and sends it to the payment service in an HTTP header. Both services log it.

Common mistake

Writing ten log lines per request with no shared id. The lines of different requests interleave, and nobody can tell which belong together.

Check yourself: 1. What is a work unit? 2. Why is one rich event better than many small lines? 3. What field lets you join the caller's event to the callee's?