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. 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. 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.

    import { 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(),
      ],
    }));

    How to set the release at build time
  3. 3

    Add hooks

    Server

    src/hooks.server.ts reports unexpected errors and scopes each HTTP request. Always pass building so prerender does not send events. If you already export init, handle, or handleError, 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.ts reports unexpected errors in the browser. Replace app.example.com with 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_DSN and PUBLIC_RASPUTIN_RELEASE in your local .env before 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. 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