Installation
Install the SvelteKit SDK, add the Vite plugin, and wire server and client hooks. Use adapter-node on a long-running Node process. 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
Add the plugin before
sveltekit(). It instruments client and SSR code. PassprojectApiKeyonly here, not in 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
hooks.server.tsreports errors and scopes HTTP. Passbuildingduring prerender. Forward existinginit,handle, orhandleErrorvia the matching options.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
hooks.client.tsreports browser errors. Gate on your production hostname so local and preview tabs stay quiet. No project API key on the client.Define
PUBLIC_RASPUTIN_DSNandPUBLIC_RASPUTIN_RELEASEin.env(empty locally is fine). Production builds need real values.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
Unexpected errors report from hooks. HTTP is already instrumented for the runtime recorder. Production needs adapter-node. Serverless adapters are not supported.
Optional: tune the runtime recorder
