mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem We need simple counts of every pageview and every global crash for SLO monitoring. These counts need to go to observability ingest, not to Sentry, etc., so they can be part of our Grafana dashboards pipeline. ## Solution - `usePageviewMetric` sends one `pageview` event on first load (hydration) and on every client-side navigation that changes the pathname. Changes to only the query string or hash do not count. - A `global_crash` event is sent once when the global crash screen is shown. That covers both the root `ErrorBoundary` and the root route `errorComponent`. Chunk-load errors that are recovered by an automatic reload are not counted, which matches what is reported to Sentry. - Both are gated by a new `IS_STAGING_OR_PREVIEW` constant. It is false on production, local development, self-hosted and Nimbus. - The request is a fire-and-forget `fetch` with `keepalive: true` and `credentials: 'omit'`. It uses a `text/plain` body, so there is no CORS preflight. Errors are swallowed. - The endpoint origin is added to `connect-src` for all platform environments, because production will need it later. No other CSP directive changes. ## Review instructions 1. Open the Studio preview deployment for this PR with the network panel open. 2. Load any page. See one `POST /api/metrics` request that returns 204. 3. Navigate to another page. See one more request. 4. Change only a query parameter (for example a table filter). See no new request. ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)