Installation

Install the SvelteKit SDK, add the Vite plugin, and wire server hooks. Use adapter-node on a long-running Node process. The plugin instruments SSR for the runtime recorder.

  1. 1

    Install the package

    Add the SvelteKit SDK to your app. It covers the Vite plugin and server hooks.

    npm install @rasputin-ai/sveltekit

  2. 2

    Add the Vite plugin

    Add the plugin before sveltekit(). It instruments SSR modules. Pass projectApiKey so the plugin can upload the server instrumentation manifest.

    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 server hooks

    hooks.server.ts reports errors and scopes HTTP. Pass building during prerender. Forward existing init, handle, or handleError via 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: 'production',
    });
    
    const rasputin = rasputinServerHooks({
      server,
      building,
    });
    
    export const init = rasputin.init;
    export const handle = rasputin.handle;
    export const handleError = rasputin.handleError;

  4. 4

    That's it

    Unexpected errors report from server hooks. HTTP is already instrumented for the runtime recorder. Production needs adapter-node. Serverless adapters are not supported.

    Tune the runtime recorder