SvelteKit

Sentry's SvelteKit SDK enables automatic reporting of errors and performance data.

The minimum supported SvelteKit version is 1.0.0 but we recommend using SvelteKit version 1.24.0 or newer for best performance. This SDK works best with Vite 4.2 and newer. Older Vite versions might not generate source maps correctly.

On this page, we get you up and running with Sentry's SDK.

If you're seeing deprecation warnings in your code, please note that we're currently working on version 8 of the JavaScript SDKs. In v8, some methods and properties will be removed or renamed. Check out the Migration docs and learn how to update your code to be compatible with v8.

Don't already have an account and Sentry project established? Head over to sentry.io, then return to this page.

Sentry captures data by using an SDK within your application’s runtime.

We recommend installing the SDK by running our installation wizard in the root directory of your project:

Copied
npx @sentry/wizard@latest -i sveltekit

The wizard will prompt you to log in to Sentry. It will then automatically do the following steps for you:

  • create or update SvelteKit files with the default Sentry configuration:
    • hooks.(client|server).js to initialize the SDK and instrument SvelteKit's hooks
    • vite.config.js to add source maps upload and auto-instrumentation via Vite plugins.
  • create a .sentryclirc file with an auth token to upload source maps (this file is automatically added to .gitignore)
  • add an example page to your app to verify your Sentry setup

After the wizard setup is completed, the SDK will automatically capture unhandled errors, and monitor performance. You can also manually capture errors.

Configuration should happen as early as possible in your application's lifecycle.

To complete your configuration, add options to your Sentry.init() calls. Here you can also set context data - data about the user, for example, or tags, or even arbitrary data - which will be added to every event sent to Sentry.

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.

Add a button to a frontend component that throws an error:

src/routes/sentry/+page.svelte
Copied
<button
  on:click={() => {
    throw new Error("Sentry Frontend Error");
  }}
>
  Throw error
</button>

Or throw an error in one of your load functions:

src/routes/sentry/+page.js
Copied
export const load = () => {
  throw new Error("Sentry Load Error");
};

Or throw an error in an API route:

src/routes/sentry/+server.js
Copied
export const GET = () => {
  throw new Error("Sentry API Error");
};

The possibilities are endless!

To view and resolve the recorded error, log into sentry.io and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").