Installation
Install with Wizard
The easiest way to set up Sentry in SvelteKit is using the Sentry Wizard:The wizard will:
- Install the
@sentry/sveltekitpackage - Create hooks files for client and server
- Configure Vite for source maps
- Set up automatic error tracking
Version Compatibility
- SvelteKit 2.0+: Fully supported
- Svelte 5: Full support including runes
- Vite 4.2+: Required for proper source map generation
Basic Setup
Client-Side Configuration
Createsrc/hooks.client.ts:
Server-Side Configuration
Createsrc/hooks.server.ts:
Vite Configuration
Add Sentry to yourvite.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 thesentryHandle() function.
Custom Spans
Database Queries
Context and User Information
Setting User Context
Adding Context
Session Replay
Enable session replay for debugging:Adapter-Specific Configuration
- Vercel
- Netlify
- Cloudflare Pages
- Node
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
Errors Not Captured
Errors Not Captured
Ensure:
- Both
hooks.client.tsandhooks.server.tsare properly configured sentryHandle()is called in the handle sequence- DSN is correctly set in both client and server configs
Source Maps Not Working
Source Maps Not Working
Verify:
- Vite plugin is configured with correct auth token
- Source maps are generated during build
organdprojectvalues 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