SvelteKit
We've 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 make the switch.
- A Sentry account and Project.
- Recommended: Latest version of our JavaScript SDK.
Don't have a Sentry account? Sign up for Sentry for free, 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:
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 hooksvite.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
<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
export const load = () => {
throw new Error("Sentry Load Error");
};
Or throw an error in an API route:
src/routes/sentry/+server.js
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.
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").