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.

The SvelteKit SDK is designed to work out of the box with the following SvelteKit adapters:

  • Adapter-auto - for Vercel; other platforms might work but we don't guarantee compatibility at this time.
  • Adapter-vercel - only for Node (Lambda) runtimes, not yet Vercel's edge runtime.
  • Adapter-node.

Other adapters may work but aren't currently supported. We're looking into extending first-class support to more adapters in the future.

The SvelteKit SDK does not yet work with non-node server runtimes, such as Vercel's edge runtime or Cloudflare Workers.

We have recently released v8 of the JavaScript SDKs. If you're using version 7.x, we recommend upgrading to the latest version. Check out the Migration docs to 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.

If the setup through the wizard doesn't work for you, you can also set up the SDK manually.

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!

Errors triggered from within Browser DevTools are sandboxed and will not trigger error monitoring. Keep this in mind when verifying your Sentry SDK installation.

Learn more about manually capturing an error or message in our Usage documentation.

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").