Workbench / Volume 2 Companion: The Web Frontend
V2·32
Frontend Observability
Companion to Volume 2, chapter 32: how errors, field performance, traces and releases connect; new angles (RUM as a hospital's ward rounds against the lab's tests, a source map as a book's index, sampling as an opinion poll); what the chapter simplifies, measured on the build's stage 32: a kitchen display that never sends on hide, sendBeacon's 64 KB budget shared by every beacon in flight, and a first frame that names the helper rather than the bug; the theory behind percentiles and cardinality; how the web-vitals library estimates INP and when it stops watching LCP; four debugging drills; interview questions with how to approach each.
Understanding it better
Concept map
Chapter 32 has four parts: errors (why the frontend is a blind spot, error tracking, source maps), performance (real-user monitoring and Web Vitals in the field), logs and traces (frontend logs, distributed traces, correlation IDs) and users and releases (session context, release health, the full picture from browser to database).
The links worth remembering:
- Every signal needs the same three tags: release, page type, and a way to join it to the server. Without the release you can't see a regression; without the page type you can't compare like with like; without a correlation ID a browser error and the server request behind it are two mysteries instead of one.
- What you collect is bounded by cost and privacy, not by what's possible. Each new tag value is a new series (cardinality); each new field is something that might hold personal data. Stage 32's endpoint drops a URL's query string for both reasons.
- Field data finds, lab data explains. RUM says the p75 LCP on tablets doubled after a release; a lab profile of that release says why.
Explain it differently
1. Lab tests are blood tests; RUM is ward rounds. A blood test is precise and repeatable, on one sample. Ward rounds see every patient as they are, less precisely, and notice who is getting worse. A hospital needs both, and so does a web app.
2. A source map is a book's index for a book that's been reprinted in tiny type. The page and line in the reprint (the minified file) tell you nothing; the index (the map) tells you which chapter and paragraph of the original it came from.
3. Percentiles are queue positions. p75 is "the 75th person of 100 in the queue waited this long". The average is the total waiting time divided by everyone, which one person waiting all day can distort.
4. Sampling is an opinion poll. You don't ask every voter; a well-chosen 1% tells you the answer within a known margin. A badly chosen one (only users who stay long enough to send a beacon) tells you something precise and wrong.
5. Cardinality is the number of drawers in a filing cabinet. One drawer per page type is manageable; one drawer per URL with its query string is a cabinet the size of the building.
6. A correlation ID is a parcel's tracking number. Each depot (browser, gateway, server, database) scans the same number, so the parcel's whole journey can be reassembled.
7. Release health is a before-and-after photo. The same metrics, side by side, for the old and new release; any difference is the release's doing until shown otherwise.
Gaps and misconceptions
What the chapter oversimplifies
All outputs are real, from Chromium 153 headless and the build's stage 32 (exp/32), unless stated.
1. "Send on visibilitychange" assumes the page is eventually hidden. The chapter recommends sending telemetry when the page becomes hidden, which is right for most pages: unload events are unreliable, and mobile browsers may kill a hidden page without warning. A kitchen display is never hidden:
kitchen page open 5 s, never hidden: beacons 2, lines dropped 2
after it navigated away: beacons 3, lines dropped 2
(The first two beacons are the experiment's own size tests.) The kitchen page sent nothing while it was open and its one beacon only when it navigated away. A display that runs all day would report at the end of the day, or never if the tablet's battery died first. Stage 32 also sends every 60 s; kiosks, dashboards, TV screens and long-running single-page apps all need the same. The sample this bias produces is subtle: "send on hide" over-represents short visits.
2. sendBeacon has a budget, and it's shared. The chapter presents sendBeacon as fire-and-forget. In Chromium:
sendBeacon accepted: [['1 KB', True], ['16 KB', True], ['63 KB', False], ['64 KB', False], ['65 KB', False], ['200 KB', False]]
two of 40 KB in a row: [True, False]
63 KB was refused, though it's under 64 KB, because 17 KB were still in flight: the limit (64 KiB) covers all beacons and keepalive fetches a page has queued and not yet sent. Two 40 KB beacons in a row: the second is refused. sendBeacon returns false rather than throwing, so a client that ignores the return value loses data silently. Keep payloads small (stage 32 caps a batch at 400 short lines) and check the result.
3. An error's first frame is where it was thrown, not where it went wrong. Error trackers group by stack, often by the top frame. Stage 32's contract error, from a minified, hashed chunk, symbolicated:
error x1 235ec3e89f | stream | ContractError: KitchenSnapshot.orders[0].kitchenId: expected a string, got undefined | /assets/chunk-WFQNUQTU.js:1:1145
/assets/chunk-WFQNUQTU.js:1:1145 -> web/contract.js:5:43
contract.js:5:43 is fail, the helper that throws for every contract violation, so every contract error everywhere has the same first frame. Grouping by it would merge unrelated bugs; grouping by message alone would split one bug into many if messages contain ids. Good grouping uses the message with variable parts removed, the place the error was reported (stream), the release, and the first frame that isn't a known helper. Error trackers let you mark frames as "not in app" for exactly this.
Common misconceptions
| Misconception | What's actually true | Where it's shown |
|---|---|---|
| "Send on hide and you'll get everything." | A page that's never hidden sends nothing. | Gaps 1 |
"sendBeacon always sends." |
It refused 63 KB with 17 KB in flight, and said so only by returning false. | Gaps 2 |
| "Group errors by their top frame." | The top frame was the shared helper fail. |
Gaps 3 |
| "INP is the slowest interaction." | It's about the 98th percentile: web-vitals takes the (n/50)th longest. | Code walkthrough |
| "Source maps are harmless to serve." | They publish your source, and nothing needs them but your error tool. | Stage 32, step 3 |
| "More tags make better data." | Each value is a new series; unbounded tags exhaust storage. | Explain it differently 5 |
| "Field LCP is the same as lab LCP." | Field LCP stops at the first input, and includes real networks and devices. | Code walkthrough |
Theoretical gaps: the ideas behind the chapter
1. Order statistics and their error. A percentile from n samples has a confidence interval that shrinks roughly with √n and is wider in the tails: a p95 from 20 samples is nearly the maximum. Release health needs enough samples per release before a difference means anything (the chapter's P6).
2. Survivorship bias. Telemetry comes from pages that lived long enough to send it. Users who left because the page was too slow, or whose browser crashed, are missing from exactly the data meant to show slowness.
3. Cardinality and the cost of dimensions. The number of series is the product of each tag's distinct values. Time-series databases price and fail by series count, which is why page paths are normalised and user ids are never tags.
4. Distributed tracing as causal ordering. A trace is a tree of spans with parent ids, a practical form of Lamport's happened-before relation across processes; W3C Trace Context's traceparent carries the trace id and parent span id between them.
5. Privacy by design and data minimisation. GDPR's data minimisation principle (collect only what's necessary for the purpose) turns into engineering rules: no query strings, no free text, short retention, and documented purpose per field (ADR-0034).
Applying it
Code walkthrough
Stage 32's INP and LCP follow the web-vitals library, which most RUM tools use. Excerpts from web-vitals 5.1.0 (dist/modules), installed from npm.
INP: an estimate of the 98th percentile
From lib/InteractionManager.js:
// To prevent unnecessary memory usage on pages with lots of interactions,
// store at most 10 of the longest interactions to consider as INP candidates.
const MAX_INTERACTIONS_TO_CONSIDER = 10;
_estimateP98LongestInteraction() {
const candidateInteractionIndex = Math.min(this._longestInteractionList.length - 1, Math.floor(getInteractionCountForNavigation() / 50));
return this._longestInteractionList[candidateInteractionIndex];
}
INP is not the slowest interaction: with fewer than 50 interactions it is the slowest, with 50 to 99 the second slowest, and so on: one in fifty ignored, which approximates the 98th percentile. Only the ten longest are kept, so memory stays constant: on a page with 500 interactions the estimate is the tenth longest, and the list holds exactly enough. The count is all interactions (interactionCount), not just the slow ones recorded. Stage 32's first version reported the maximum, so one slow tap in a day of kitchen use would have defined the page; it now does the same estimate.
Interactions are grouped
let interaction = this._longestInteractionMap.get(entry.interactionId);
// Only process the entry if it's possibly one of the ten longest,
// or if it's part of an existing interaction.
if (interaction ||
this._longestInteractionList.length < MAX_INTERACTIONS_TO_CONSIDER ||
// If the above conditions are false, `minLongestInteraction` will be set.
entry.duration > minLongestInteraction._latency) {
// If the interaction already exists, update it. Otherwise create one.
if (interaction) {
// If the new entry has a longer duration, replace the old entries,
// otherwise add to the array.
if (entry.duration > interaction._latency) {
interaction.entries = [entry];
interaction._latency = entry.duration;
}
One tap produces several events (pointerdown, pointerup, click) with the same interactionId; the interaction's latency is the longest of them. Counting events instead of interactions would triple the count and shift the estimate.
LCP stops at the first input
From onLCP.js:
// Stop listening after input or visibilitychange.
// Note: while scrolling is an input that stops LCP observation, it's
// unreliable since it can be programmatically generated.
// See: https://github.com/GoogleChrome/web-vitals/issues/75
for (const type of ['keydown', 'click', 'visibilitychange']) {
addEventListener(type, stopListeningWrapper, {
capture: true,
});
}
The browser itself stops issuing LCP candidates after user input, and the library reports the final value at the first trusted keydown, click or hide (in an idle callback, so reporting doesn't slow the interaction it follows). Stage 32's client keeps the last candidate it observed, which matches because the browser stops sending them.
Debugging drills
D1. No data from kitchens, plenty from the menu
The RUM summary shows hundreds of menu page views per day and almost no kitchen display data, though every kitchen has a display open all day.
D2. All contract errors are one issue
The error tracker shows a single, huge "ContractError at fail (contract.js)" issue; three different bugs are hidden in it.
D3. The summary runs out of series
After a week the RUM summary stops accepting new metrics, and drops climb.
D4. Symbolicated frames point at the wrong lines
After a deploy, symbolicated frames from some users point at lines that can't have thrown.
Career-oriented
Interview prep
Mid-level 1: why percentiles?
Question. "Our average page load is 1.2 s. Is that good?"
How to get there. Say what the average hides, and what you'd ask for instead.
Mid-level 2: what should a frontend error report contain?
Question. "Design the payload your app sends when it catches an error."
How to get there. What's needed to find, group and fix it; what must not be included.
Senior 1: tie a browser error to the backend
Question. "Users report 'checkout failed'. The frontend logs an error; the backend logs show many 500s. How do you connect them?"
How to get there. A shared id, how it's created and propagated, and what each side records.
Senior 2: is the new release worse?
Question. "After a release, p75 INP went from 180 ms to 210 ms. Do you roll back?"
How to get there. Is the difference real, is it the release, and how bad is it.
Staff 1: build or buy
Question. "Should we build our own RUM and error pipeline or buy a product?"
How to get there. What each costs over time, what you'd lose, and what has to stay yours either way.
Staff 2: an observability standard for all teams
Question. "Five frontend teams instrument differently. What standard do you set?"
How to get there. Names, tags, privacy and ownership, with enforcement.