Installation
Install the SvelteKit SDK, add the Vite plugin, and wire server and client hooks. That is enough for error reporting. The plugin also instruments the app for the runtime recorder.
- 1
Install the package
Add the SvelteKit SDK to your app. It covers the Vite plugin, server hooks, and client hooks.
npm install @rasputin-ai/sveltekit - 2
Add the Vite plugin
Register the plugin before
sveltekit(). It instruments client and SSR modules. It does not start reporting. Pass projectApiKey only to the plugin; never to client hooks.How to set the release at build timeimport { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; import { rasputin } from '@rasputin-ai/sveltekit/vite'; export default defineConfig(({ command }) => ({ plugins: [ rasputin({ enabled: command === 'build', release: process.env.RASPUTIN_RELEASE!, projectApiKey: process.env.RASPUTIN_PROJECT_API_KEY, }), sveltekit(), ], })); - 3
Add hooks
Server
src/hooks.server.tsreports unexpected errors and scopes each HTTP request. Always passbuildingso prerender does not send events. If you already exportinit,handle, orhandleError, pass those functions as options of the same name.import { rasputinServerHooks } from '@rasputin-ai/sveltekit'; import { node } from '@rasputin-ai/sveltekit/runtime/node'; import { building } from '$app/environment'; const server = node({ dsn: process.env.RASPUTIN_DSN!, projectApiKey: process.env.RASPUTIN_PROJECT_API_KEY!, release: process.env.RASPUTIN_RELEASE!, environment: process.env.NODE_ENV ?? 'development', enabled: ['staging', 'production'].includes(process.env.NODE_ENV ?? 'development'), }); const rasputin = rasputinServerHooks({ server, building, }); export const init = rasputin.init; export const handle = rasputin.handle; export const handleError = rasputin.handleError;Client
src/hooks.client.tsreports unexpected errors in the browser. Replaceapp.example.comwith your production hostname so local and preview browsers do not send events. If your app uses multiple production hostnames, adjust the check to include each one. Do not pass a project API key.PUBLIC_variables are inlined at build time.Define
PUBLIC_RASPUTIN_DSNandPUBLIC_RASPUTIN_RELEASEin your local.envbefore using these named imports. They may be empty while the client is disabled locally. A missing static export prevents the browser app from starting, including client-side navigation. Set real values for production builds.import { rasputinClientHooks } from '@rasputin-ai/sveltekit/client'; import { PUBLIC_RASPUTIN_DSN, PUBLIC_RASPUTIN_RELEASE } from '$env/static/public'; // Replace this with the hostname of your production app. const productionBrowser = globalThis.location?.hostname === 'app.example.com'; const rasputin = rasputinClientHooks({ dsn: PUBLIC_RASPUTIN_DSN ?? '', environment: productionBrowser ? 'production' : 'development', release: PUBLIC_RASPUTIN_RELEASE ?? '', enabled: productionBrowser, }); export const init = rasputin.init; export const handleError = rasputin.handleError; - 4
That's it
Rasputin reports unexpected errors from hooks. The Vite plugin instruments the app, so the runtime recorder is already on for HTTP requests.
Optional: tune the runtime recorder
