Skip to content

feat(analytics): log visitor requests with a hashed caller - #18

Merged
jm-rivera merged 2 commits into
devfrom
feat/request-log-caller
Oct 20, 2026
Merged

jm-rivera merged 2 commits into
devfrom
feat/request-log-caller

Conversation

@jm-rivera

@jm-rivera jm-rivera commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Cloud Run's request logs identify Cloudflare's edge address. The website writes one JSON line per page or API request with a hashed visitor address, method, pathname, host, user agent, and a kind of page, api, rsc, or prefetch. The caller digest uses the existing CALLER_HMAC_KEY and TRUSTED_PROXY_HOPS settings shared with /mcp. Raw addresses, query strings, cookies, and credentials stay out of the log. Framework assets, images, and fonts are skipped.

src/instrumentation.ts registers Node HTTP diagnostic subscribers before request handling. They read the original headers and leave request bodies unread, preserving complete streaming payloads. A response-finish fallback catches requests accepted during startup, and a shared WeakSet prevents duplicate entries across events and development reloads. Malformed requests emit a constant logging-error message.

Testing: lint, typecheck, and the production build pass, along with all 1,510 tests outside db/test. The regression tests cover an intact 11 MiB streamed body, receipt of the first chunk before upload completes, startup logging, duplicate registration, and query privacy on malformed URLs. The standalone production smoke test verifies full-body streaming, one startup entry, page/API/RSC/prefetch classification, and skipped assets. CI runs the database tests and production build.

Cloud Run's request log records Cloudflare's edge address, so visitor
counts from logs had to rely on user-agent signatures and ranged from
150 to 1,000 on launch day. src/proxy.ts now writes one JSON line per
page or API request carrying the caller digest the /mcp proxy already
sends, and tags each line page, api, rsc or prefetch.
@jm-rivera
jm-rivera marked this pull request as ready for review October 20, 2026 15:20
Observe Node HTTP diagnostics from instrumentation so API and MCP request
bodies reach their handlers intact. Deduplicate startup response logs and
keep raw request data out of logging errors.
@jm-rivera jm-rivera changed the title feat(proxy): log each visitor request with a hashed caller feat(analytics): log visitor requests with a hashed caller Oct 20, 2026
@jm-rivera
jm-rivera merged commit bf7ff1a into dev Oct 20, 2026
1 check passed
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