Skip to main content
The Sentry SvelteKit SDK provides comprehensive error monitoring and performance tracking for SvelteKit applications with support for both client and server-side rendering.

Installation

1

Install with Wizard

The easiest way to set up Sentry in SvelteKit is using the Sentry Wizard:
The wizard will:
  • Install the @sentry/sveltekit package
  • Create hooks files for client and server
  • Configure Vite for source maps
  • Set up automatic error tracking
2

Manual Installation

Version Compatibility

  • SvelteKit 2.0+: Fully supported
  • Svelte 5: Full support including runes
  • Vite 4.2+: Required for proper source map generation
Check the adapter compatibility for your deployment target.

Basic Setup

Client-Side Configuration

Create src/hooks.client.ts:

Server-Side Configuration

Create src/hooks.server.ts:

Vite Configuration

Add Sentry to your vite.config.ts:

Error Handling

Client-Side Errors

Errors in Svelte components are automatically captured:

Server Load Functions

Errors in load functions are automatically captured:

Universal Load Functions

Form Actions

Track server-side form actions:

API Routes

Performance Monitoring

Page Load Tracking

Page loads are automatically tracked with the sentryHandle() function.

Custom Spans

Database Queries

Context and User Information

Setting User Context

Adding Context

Session Replay

Enable session replay for debugging:

Adapter-Specific Configuration

No additional configuration needed. Works out of the box.

Environment Variables

Add to your .env file:

Best Practices

Separate Hooks

Always use separate hooks files for client and server initialization.

Handle Order

Place sentryHandle() first in the sequence to catch all errors.

Source Maps

Configure Vite plugin for automatic source map upload.

User Context

Set user context in a custom handle after authentication.

Troubleshooting

Ensure:
  1. Both hooks.client.ts and hooks.server.ts are properly configured
  2. sentryHandle() is called in the handle sequence
  3. DSN is correctly set in both client and server configs
Verify:
  1. Vite plugin is configured with correct auth token
  2. Source maps are generated during build
  3. org and project values are correct

Next Steps

Load Functions

Track data loading performance

Form Actions

Monitor form submissions

Session Replay

Debug with session recordings

Adapters

Configure for your deployment platform