Skip to content

Add Sentry error monitoring (edge-compatible)#719

Open
RisingOrange wants to merge 16 commits intoPauseAI:mainfrom
RisingOrange:add-sentry
Open

Add Sentry error monitoring (edge-compatible)#719
RisingOrange wants to merge 16 commits intoPauseAI:mainfrom
RisingOrange:add-sentry

Conversation

@RisingOrange
Copy link
Copy Markdown
Contributor

@RisingOrange RisingOrange commented Apr 2, 2026

Adds Sentry error monitoring so we get notified when users hit errors, with stack traces and context to debug them. Resolves #707, alternative to #714.

@sentry/sveltekit doesn't support non-Node.js edge runtimes, which includes Netlify edge functions (Deno). This PR uses the individual Sentry SDKs instead.

Approach

  • Client: @sentry/svelte in src/hooks.client.ts
  • Server: @sentry/deno (dynamically imported) in src/hooks.server.ts
  • Source maps: @sentry/vite-plugin + postbuild script for edge function maps

Details

  • DSN comes from PUBLIC_SENTRY_DSN env var (not hardcoded)
  • Tracing disabled (tracesSampleRate: 0) — not useful for a content site
  • Session replay disabled — avoids bundle bloat
  • Server-side logs enabled (enableLogs: true in @sentry/deno)
  • Release tagged with git SHA for source map symbolication
  • @sentry/deno is dynamically imported to avoid conflicts with the Netlify Deno window stub fix, and skipped during Node.js prerender
  • Both hooks use SvelteKit's init hook (since 2.10) to ensure Sentry is ready before the first request
  • Server handleError uses event.platform.context.waitUntil to flush events without blocking the error response
  • Postbuild script injects Debug IDs into edge function bundles before uploading source maps (the Vite plugin runs before adapter-netlify creates them)

Required env vars (Netlify)

  • PUBLIC_SENTRY_DSN — Sentry DSN (already configured)
  • SENTRY_AUTH_TOKEN — for source map uploads
  • SENTRY_ORG — Sentry org slug
  • SENTRY_PROJECT — Sentry project slug

Risk

@sentry/deno is in beta and may not work on Netlify's non-standard Deno edge runtime. If it fails at runtime, server-side error capture degrades silently (client-side still works). The dynamic import is wrapped in try/catch so a server SDK failure won't break the site.

Use @sentry/svelte (client) and @sentry/deno (server) instead of
@sentry/sveltekit, which doesn't support Netlify's Deno edge runtime.
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 2, 2026

👷 Deploy request for pauseai pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 1488d90

Fixes knip lint failure (unused devDependency).
@RisingOrange RisingOrange mentioned this pull request Apr 2, 2026
@Wituareard
Copy link
Copy Markdown
Collaborator

Wituareard commented Apr 2, 2026

Thanks, this doesn't capture logs yet right? That would be a neat addition but not super important. Could use the standardized waitUntil API for dispatching them (edit: and also for the errors maybe)

Add proper types to avoid unsafe-assignment and unsafe-member-access
warnings that pushed the warning count over the CI limit.
@RisingOrange
Copy link
Copy Markdown
Contributor Author

Enabled enableLogs on the server (@sentry/deno supports it, @sentry/svelte doesn't).

waitUntil isn't available in SvelteKit's handleError hook since it doesn't expose the Netlify context object. I used await Sentry.flush(2000) instead.

@Wituareard
Copy link
Copy Markdown
Collaborator

Are you sure that it isn't available under event.platform?

@RisingOrange
Copy link
Copy Markdown
Contributor Author

@Wituareard Oh, you're right. Updated to use that

@Wituareard
Copy link
Copy Markdown
Collaborator

npx didn't properly download the binary, so I had to add the CLI as a dependency

@Wituareard
Copy link
Copy Markdown
Collaborator

Source map upload works, but it produces 600 lines of log entries so that should probably be reduced

@Wituareard
Copy link
Copy Markdown
Collaborator

Nvm it was the Vite plugin that produced the logs

@Wituareard
Copy link
Copy Markdown
Collaborator

Wituareard commented Apr 2, 2026

Nothing shows up in Sentry, can't take a closer look atm unfortunately

Wituareard and others added 2 commits April 3, 2026 00:03
import.meta.env doesn't expose PUBLIC_ prefixed vars in SvelteKit.
Must use $env/dynamic/public instead.
@RisingOrange
Copy link
Copy Markdown
Contributor Author

Found the issue: hooks.client.ts was reading the DSN from import.meta.env.PUBLIC_SENTRY_DSN, which is always undefined in SvelteKit. SvelteKit doesn't expose PUBLIC_ prefixed env vars through import.meta.env, you have to use $env/dynamic/public instead. Fixed in 1488d90.

I tested with a custom Sentry project locally and confirmed client-side errors now show up.

I couldn't test server errors locally, because the dev server runs Node.js and @sentry/deno only loads on Netlify's Deno edge runtime.

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.

Add error monitoring

2 participants