Skip to content

fix(analytics): write one request line per request, closed or finished - #61

Merged
jm-rivera merged 1 commit into
devfrom
fix/request-log-fixes
Oct 24, 2026
Merged

jm-rivera merged 1 commit into
devfrom
fix/request-log-fixes

Conversation

@jm-rivera

Copy link
Copy Markdown
Contributor

The request line (src/lib/proxy/requestLog.ts) was written only when a response finished, so an abandoned page render, an aborted RSC fetch or a closed /mcp stream wrote nothing. registerRequestLogging now attaches one close listener to each response at http.server.request.start, and Node emits close after finish, so every request writes exactly one line, with finished: response.writableFinished. A response that closes before the app sends a status logs 499. A request accepted before the subscription starts is logged when it finishes.

path is the request target as it arrived, captured at request start, with dot segments resolved and //mcp kept as a path and not read as a host. An absolute-form target logs its pathname, an unparsable one the raw target cut at ? or #, and OPTIONS * logs *. A document request with Sec-Purpose: prefetch;prerender is kind page with prerender: true, while RSC fetches and router prefetches keep their kinds. Static assets are dropped before headers are read or the caller HMAC computed. The fields infra's website_requests_daily reads keep their names and types, and finished and prerender are new.

docs/analytics.md describes the line, and the export section states the account_daily threshold and the export_rules reload, which #60 ships. Merge after #60.

Testing: the proxy tests pass (103), including real HTTP servers for finish, early close, a close before headers, a rewritten request.url and a streamed upload over 10 MiB. Each new test fails without its change.

registerRequestLogging attaches one close listener per response, so a request
writes exactly one line with a finished flag, and a response that closes
before the app sends a status logs 499. The path is the request target as it
arrived, normalised without reading // as a host. A document prerender is
kind page with a prerender flag. Static assets are dropped before the caller
HMAC is computed. docs/analytics.md describes the line and the account and
event export rules.
@jm-rivera
jm-rivera merged commit 1d34ca8 into dev Oct 24, 2026
1 check passed
@jm-rivera
jm-rivera deleted the fix/request-log-fixes branch October 24, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant