Skip to content

feat(obs): a click becomes the parent of the SQL it causes (telemetry P20b) - #484

Merged
athvin merged 2 commits into
mainfrom
bm/telemetry-p20b-click-stream
Nov 5, 2026
Merged

athvin merged 2 commits into
mainfrom
bm/telemetry-p20b-click-stream

Conversation

@athvin

@athvin athvin commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

The last link in "trace a session from what buttons they clicked to what happened on the backend".

Before this a trace started at the BFF: you could see that a job ran and every statement it executed — and not which button caused it. Now one delegated capture-phase listener mints a context per named click, bffFetch/arrowFetch attach it, and through #481 the job, run, stages and all 245 statements hang off that click.

Capture phase because the controls worth measuring are the ones inside rows and menus, and those routinely stopPropagation. One listener on document rather than per-component, so nothing has to opt in and there is no lifecycle to leak.

Two places the convenient behaviour would be a lie

A lapsed click is not reused. The context lives 1000 ms; a request after that attaches to a per-page-load background root. A debounced search, a poll, a refetch-on-focus genuinely have no click behind them, and attributing them to whatever was last pressed would assert causation that does not exist. "The page did this" is less satisfying and true.

An unnamed click mints nothing. Most clicks land on text and scroll regions; naming them from the tag would turn reading into a priced stream of "interactions".

Both tested, and both observed failing on exactly their own regression:

regression fails
drop the TTL check does NOT reuse a click once its TTL has lapsed (only)
mint for unnamed targets mints nothing for an unnamed click (only)

The beacon, and the case it exists for

A click is queued the moment it happens, not when a request fires — so a button with no network effect is still visible. Without that, an action with no backend call leaves no trace at all and is indistinguishable from the person never clicking, which is the case your original ask named explicitly.

sendBeacon on visibilitychange/pagehide, because fetch is cancelled on unload and the last click before a navigation is the one most worth having — pagehide too, since Safari does not reliably fire the former. A plain fetch on the 5 s timer, where a status is worth having. Queue bounded at 200 with a reported drop count.

/api/telemetry, and what the browser is not trusted for

Same-origin rather than browser-to-collector: the collector is cluster-internal with ingress.enabled: false, and exposing it would mean a public unauthenticated telemetry ingest in front of the one component that bills by the byte. Going through the BFF also gets the session cookie, org scoping and a server-side allowlist for free.

  • Session id and user come from the httpOnly cookie, read server-side — never from the body. Identity.sessionId is deliberately never given to the browser, so it cannot be forged into a beacon.
  • The action name is length-bounded; the traceparent is validated against the same rule erserver applies; anything else in the body is ignored rather than forwarded — a field nobody reads is a field nobody has to sanitise.
  • A malformed entry is dropped rather than 400'ing the batch: a beacon has no one to report an error to, so rejecting would lose the good entries with the bad.

check-bff-authz.mjs gains the telemetry entry in this commit, because findUncoveredApiDirs hard-fails on an unknown api directory. It requires requireIdentity rather than sitting in UNAUTHENTICATED_DIRS beside csp-report, which genuinely has no session.

Deliberately not here

  • Forwarding to the collector, which needs an OTLP encoder on the Node side. Landing the ingest first means the browser half can be exercised and its PII boundary reviewed before anything is exported; until then interactions are logged, which Fluent Bit already ships in-account.
  • The closed UI_ACTIONS vocabulary and its bidirectional gate. The gate needs data-er-action attributes to exist, so it lands with the pass that annotates components rather than as a const nothing reads. Resolution already falls back to data-testid, which most interactive elements carry, so this works today.

pnpm check passes: 845 tests, all four gates, the coverage floor.

🤖 Generated with Claude Code


Added after first review: a PII leak in the resolver this PR introduced

The first version of resolveActionName walked data-er-action →
data-testid → aria-label, on the stated reasoning that only textContent
could carry a record value. That reasoning was wrong to stop at textContent.

aria-label={`Remove ${member.email}`}           // settings/members-list.tsx
data-testid={`member-remove-${member.email}`}   // the same element
aria-label={`Split out ${member.record_key}`}   // records/entity-view.tsx

27 of 63 aria-label sites in this app are interpolated, and what they
interpolate is the payload. A click on "remove member" resolved to
[email protected].

None of those call sites is wrong, and none is changing. A screen reader
user needs to know which member; a Playwright test needs to address one row.
Accessibility and telemetry want opposite things from the same attribute, so
telemetry now has its own, with a closed UI_ACTIONS vocabulary enforced in
three places: the resolver at runtime, POST /api/telemetry at the boundary,
and scripts/check-er-actions.mjs at build time.

The gate fails three ways — an undeclared name emitted, a declared name
nothing emits (which reads as coverage rather than an error), and a
non-literal action argument, which is how the hole would reopen. All three
arms were observed failing before being trusted.

And a coverage hole found while annotating

The two highest-volume decision surfaces are keyboard-first and say so with
<kbd> hints — review binds m/n/x, labelling m/n/s.
labeling-content.tsx states why: "reaching for a mouse per pair is the
difference between labelling 20 and 200."
A click-only listener records
nothing for the steward who resolves the most pairs, and no DOM event bridges
the gap — a keydown says which key, not which action the page ran. Those
surfaces now report through recordAction from the funnel their buttons
already share, after each early return, with source separating the paths.
Those buttons carry no data-er-action on purpose: both would double-count.

13 actions declared, all emitted; 382 files examined; 852 tests pass.

@athvin
athvin force-pushed the bm/telemetry-p20b-click-stream branch 3 times, most recently from 987656d to 28fa980 Compare November 5, 2026 11:27
bmoore813 and others added 2 commits November 5, 2026 06:34
… P20b)

The last link in "trace a session from what buttons they clicked to what
happened on the backend". Before this a trace started at the BFF: you could see
that a job ran and every statement it executed, and not which button caused it.

One delegated capture-phase listener on `document`, installed in `AppShell`.
A named click mints a W3C context; `bffFetch`/`arrowFetch` attach it, so
er-server's spans — and through P9, the job's, the run's, the stages' and all
245 statements' — hang off the click.

Capture phase, because the controls worth measuring are the ones inside rows
and menus and those routinely `stopPropagation`. One listener rather than
per-component, so nothing has to opt in and there is no lifecycle to leak.

## Two places the convenient behaviour would be a lie

**A lapsed click is not reused.** The context lives 1000 ms; a request after
that attaches to a per-page-load `background` root instead. A debounced search,
a poll, a refetch-on-focus genuinely have no click behind them, and attributing
them to whatever was last pressed would assert causation that does not exist.
"The page did this" is less satisfying and true.

**An unnamed click mints nothing.** Most clicks land on text and scroll
regions. Naming them from the tag would turn reading into a priced stream of
interactions.

Both are tested, and both tests were observed failing on exactly their own
regression: dropping the TTL check fails only the staleness test, and minting
for unnamed targets fails only the unnamed test.

## The beacon, and the case it exists for

A click is queued the moment it happens, not when a request fires — so a button
with NO network effect is still visible. Without that, an action with no
backend call leaves no trace at all and looks indistinguishable from the person
never having clicked, which is the case the original ask named.

`sendBeacon` on `visibilitychange`/`pagehide` because `fetch` is cancelled on
unload and the last click before a navigation is the one most worth having;
`pagehide` as well, since Safari does not reliably fire the former. A plain
`fetch` on the 5 s timer, where a status is worth having. The queue is bounded
at 200 with a reported drop count.

## /api/telemetry, and what the browser is not trusted for

Same-origin, not browser-to-collector: the collector is cluster-internal with
`ingress.enabled: false`, and exposing it would mean a public unauthenticated
ingest in front of the component that bills by the byte. Going through the BFF
also gets the session cookie, org scoping and a server-side allowlist for free.

The session id and user come from the httpOnly COOKIE, read server-side — never
from the body. `Identity.sessionId` is deliberately never given to the browser,
so it cannot be forged into a beacon. The action name is length-bounded and the
traceparent is validated against the same rule erserver applies; anything else
in the body is ignored rather than forwarded.

A malformed entry is dropped rather than 400'ing the batch: a beacon has no one
to report an error to, so rejecting would lose the good entries with the bad.

`check-bff-authz.mjs` gains the `telemetry` RULES entry in this commit, because
`findUncoveredApiDirs` hard-fails on an unknown api directory — and it requires
`requireIdentity` rather than sitting in UNAUTHENTICATED_DIRS beside
csp-report, which genuinely has no session.

## Deliberately not here

Forwarding to the collector, which needs an OTLP encoder on the Node side.
Landing the ingest first means the browser half can be exercised and its PII
boundary reviewed before anything is exported; until then interactions are
logged, which Fluent Bit already ships in-account.

The closed `UI_ACTIONS` vocabulary and its bidirectional gate also wait: the
gate needs `data-er-action` attributes to exist, so it lands with the pass that
annotates components rather than as a const nothing reads.

`pnpm check` passes: 845 tests, all four gates, the coverage floor.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…that hold emails

`resolveActionName` walked `data-er-action` -> `data-testid` -> `aria-label`,
on the reasoning that only `textContent` could carry a record value. That
reasoning was wrong to stop at `textContent`.

In this app:

    aria-label={`Remove ${member.email}`}           // settings/members-list.tsx
    data-testid={`member-remove-${member.email}`}   // the same element
    aria-label={`Split out ${member.record_key}`}   // records/entity-view.tsx
    data-testid={`mark-${member.record_key}`}       // the same element

27 of 63 `aria-label` sites are interpolated, and what they interpolate is
exactly the payload a deduplication engine holds. A click on "remove member"
resolved to `[email protected]`, which then travelled to the span
store -- against the one prohibition in infrastructure.md §10.4, which says
telemetry carries identifiers and counts and never attribute values, and
against the rule that plaintext email stays in the audit trail.

None of those call sites is a mistake and none is changing: a screen reader
user needs to know which member the button removes, and a Playwright test
needs to address one row of many. Accessibility and telemetry want opposite
things from the same attribute, so telemetry gets its own.

So the name now comes from `data-er-action` alone, and its value must be a
member of a closed `UI_ACTIONS` vocabulary -- checked at runtime by the
resolver, at the boundary by `POST /api/telemetry`, and at build time by
`scripts/check-er-actions.mjs`, which fails the gate in three ways: an
emitted name that is not declared, a declared name nothing emits (which
reads as coverage -- an empty chart rather than an error), and an action
argument that is not a plain string literal, which is how the hole would
reopen. All three arms were observed failing before being trusted.

Also closes a coverage hole found while annotating. The two highest-volume
decision surfaces are keyboard-first and say so in the UI with `<kbd>` hints
-- the review inbox binds m/n/x, labelling binds m/n/s -- and
labeling-content.tsx states the reason outright: "reaching for a mouse per
pair is the difference between labelling 20 and 200". A click-only listener
records nothing for the steward who resolves the most pairs. No DOM event
bridges that gap, since a keydown says which key was pressed and not which
action the page ran, so those surfaces report through `recordAction` from the
funnel their buttons already share, with `source` distinguishing the two
paths. Reporting sits after each handler's early return, so a press that
does nothing records nothing, and those buttons deliberately carry no
`data-er-action` -- both together would count one verdict twice.

13 actions declared, all emitted; 382 files examined; 852 tests pass.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin force-pushed the bm/telemetry-p20b-click-stream branch from 28fa980 to 35036fe Compare November 5, 2026 11:35
@athvin athvin added the merge-bus eligible for the merge bus label Nov 5, 2026
@athvin
athvin merged commit 2205e46 into main Nov 5, 2026
39 checks passed
@athvin
athvin deleted the bm/telemetry-p20b-click-stream branch November 5, 2026 11:56
athvin added a commit that referenced this pull request Nov 5, 2026
…#503)

The trace already reached from a click to every SQL statement a run executed.
What it could not say is which control started it: a reader looking at a slow
statement could see it belonged to some click, and had to walk up to the root
span to find out which. The question people actually ask — "what does the
Merge button do to the database?" — needed the control's name ON the backend
span.

So the declared action travels browser -> BFF -> erserver as `x-er-action`,
beside the `traceparent` that was already going. One header, three hops, and
`er.action` on `http.server`.

Three deliberate choices:

**Shape-validated in erserver, not membership-checked.** The authoritative
vocabulary is TypeScript, and duplicating `UI_ACTIONS` in Rust would create a
two-language list that drifts silently in whichever direction nobody is
testing. The build gate is the real guarantee; this is the untrusted-input
bound underneath it. Shape is enough for what it must prevent: lowercase,
digits, dots and underscores with at least one dot refuses every payload shape
that matters here, because an email carries `@`, a record key carries
uppercase or hyphens, and a query string carries `=` and `&`. The test asserts
that against real strings from this app's own markup — including the
`[email protected]` testid and the `Remove [email protected]`
aria-label that caused the PII fix in #484.

**Validated again at the BFF, against the real vocabulary.** The browser is
not trusted, and an unrecognised name is either a typo the er-actions gate
should have caught or something hostile. Dropping it is right in both cases,
because an action name reaches a span store.

**Span-only, never a metric dimension.** The vocabulary grows with the UI, and
a per-action series is the cardinality mistake §10 already priced at
~$131/month for one histogram. A per-action aggregate, if ever wanted, is a
`spanmetrics` connector in the collector's values file.

The background root is NOT sent. It is not something anybody did, and sending
it would make "no click" indistinguishable from a declared action in any
grouping. Nor is a lapsed one: a poll firing a second after a click gets no
action, which the TTL test asserts.

This also makes the seventh tail_sampling policy possible, which the plan
listed and which has been absent because there was no attribute to key on. A
click causing a mutation was already kept by `mutations` and one starting a
run by `pipeline-runs`; what fell through was the click causing a GET —
opening a record, filtering the inbox, paging a table — which landed in
`residual` and was dropped 90% of the time. That is the half of the click
stream most likely to be asked about, and its volume is tiny next to the read
path it sits in.

make check exit 0; pnpm check exit 0, 874 tests, 13 declared actions all
emitted.

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
athvin added a commit that referenced this pull request Nov 5, 2026
…"red" (#502)

Cosmetic but misleading. `mergeStateStatus: UNSTABLE` covers a non-required
check that is red *or* one that has not finished, and the bus reported it as

    #484   skip   a non-required check is red (UNSTABLE)

while #484 was in fact only queued on `record pass marker`. It went CLEAN by
itself a few minutes later. Anyone reading that table would have gone hunting
for a failure that did not exist.

Behaviour is unchanged and was already correct: the bus takes only what GitHub
calls fully clean, so a merely-pending PR is skipped this round and rides the
next. Only the wording and the reasoning around it change, plus the reference
gains the two states that are refused despite being hand-mergeable — pending
and semgrep-only — so the conservatism is written down rather than rediscovered.

Noticed while dry-running the bus for a real landing. That same run verified the
#486 workflow-files exclusion in production: #498 (`deploy.yml`) was correctly
skipped with "merge it by hand".

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-bus eligible for the merge bus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants