Skip to main content
The @sentry/sveltekit package provides comprehensive error tracking and performance monitoring for SvelteKit applications, with support for both client and server environments.

Prerequisites

  • Node.js 18 or newer
  • SvelteKit 2.0.0 or newer
  • Vite 4.2 or newer (recommended)
  • A Sentry account and project DSN
The SDK works best with Vite 4.2 and newer. Older versions might not generate source maps correctly.

Quick Installation with Wizard

The fastest way to get started is using the Sentry SvelteKit Wizard:
The wizard will:
  1. Install @sentry/sveltekit
  2. Create configuration files
  3. Set up source map uploads
  4. Configure hooks
The wizard automates the entire setup process. If you prefer manual installation, follow the steps below.

Manual Installation

1

Install the Package

Install @sentry/sveltekit using your preferred package manager:
Current Version: 10.42.0
2

Create Client Configuration

Create src/hooks.client.ts (or .js):
3

Create Server Configuration

Create src/hooks.server.ts (or .js):
4

Configure Vite

Update vite.config.ts to include Sentry’s Vite plugin:
5

Set Environment Variables

Add your Sentry auth token to .env:
Never commit your .env file to version control. Add it to .gitignore.
6

Verify Installation

Create a test page to verify Sentry is working:
Visit the page and click the button. Check your Sentry dashboard to see the error.

Error Handling

Automatic Error Capture

The SDK automatically captures:
  • Unhandled exceptions on both client and server
  • Errors in load functions
  • Errors in server endpoints
  • Errors in form actions

Custom Error Handling

You can customize error handling:

Load Functions

Errors in load functions are automatically captured:

Performance Monitoring

Automatic Instrumentation

The SDK automatically creates spans for:
  • Page loads
  • Navigation
  • Server requests
  • Load functions
  • Form actions

Custom Spans

Server-Side Usage

Server Load Functions

Form Actions

API Routes

Client-Side Usage

In Svelte Components

Setting Context

Session Replay

Configure Session Replay in your client hooks:

Adapter Compatibility

The Sentry SvelteKit SDK is compatible with most SvelteKit adapters:
  • @sveltejs/adapter-node
  • @sveltejs/adapter-vercel
  • @sveltejs/adapter-netlify
  • @sveltejs/adapter-cloudflare
  • @sveltejs/adapter-static
  • @sveltejs/adapter-auto
Some adapters may require additional configuration. Check the official documentation for adapter-specific setup.

Advanced Configuration

Environment Detection

Sampling

Custom Transport

Source Maps

Source maps are automatically handled by the Sentry Vite plugin when configured properly:

Troubleshooting

Errors Not Captured

  1. Ensure both hooks.client.ts and hooks.server.ts are configured
  2. Check that handleError is exported from both files
  3. Verify DSN is correct in both client and server configs

Source Maps Not Working

  1. Check SENTRY_AUTH_TOKEN is set correctly
  2. Verify org and project match your Sentry organization
  3. Ensure Vite is generating source maps (check vite.config.ts)

Performance Data Missing

  1. Ensure tracesSampleRate is greater than 0
  2. Check that sentryHandle() is in the hook sequence
  3. Verify Sentry is initialized before the app runs
Make sure to call Sentry.init() in both hooks.client.ts and hooks.server.ts with appropriate configurations for each environment.

Build Errors

If you encounter build errors:
  1. Update to the latest @sentry/sveltekit version
  2. Ensure Vite is version 4.2 or newer
  3. Check SvelteKit version compatibility

Next Steps