SvelteKit

Learn how to set up and configure Sentry in your SvelteKit application using the installation wizard, capture your first errors, and view them in Sentry.

Agent-Assisted Setup
Use curl to download, read and follow https://skills.sentry.dev/instrument to set up the Sentry SvelteKit SDK.
Your agent will set up Sentry in your SvelteKit app automatically. Works with Cursor, Claude Code, Codex, and more.View docs ↗
Install the full plugin

Install the Sentry plugin to give your assistant every skill. See the installation docs for more details.

Copied
npx @sentry/ai install

You need:

  • A Sentry account and project
  • Your application up and running
  • SvelteKit version 2.0.0+ (we recommend 2.31.0 or higher for best support)
  • Vite version 4.2+
I'm on an older SvelteKit version than 2.31.0

Version 2.31.0 of SvelteKit introduces official support for observability and tracing. This means that Sentry can now follow the official best practice for how the SDK should be set up:

  • The Sentry SDK will be initialized at the correct, earliest possible time on the server, allowing for all its auto-instrumentation to work correctly. This means, you will now get spans from auto instrumentation (e.g. database queries) automatically.
  • The Sentry SDK picks up spans emitted from SvelteKit directly. You'll get more accurate insights into the performance of your handlers, server actions, load, and remote functions.

SvelteKit observability is still an experimental feature in SvelteKit 2.x, but we recommend giving it a try. The Sentry wizard, as well as this guide, will use it as the default way of setting up the SDK.

If you've already set up the SDK and don't want to migrate to the new setup, or don't want to upgrade to SvelteKit 2.31.0 or higher, that's fine too. Just follow this guide instead. However, note that auto instrumentation (e.g. for database queries) will not work.

Notes on SvelteKit adapter compatibility

The SvelteKit Sentry SDK is designed to work out of the box with several SvelteKit adapters and their underlying server runtimes. Here's an overview of the current support:

  • Fully supported Node.js runtimes
  • Supported non-Node.js runtimes
  • Currently not supported
    • Non-Node.js server runtimes, such as Vercel's edge runtime, are not yet supported.
  • Other adapters
    • Other SvelteKit adapters might work, but they're not currently officially supported. We're looking into extending first-class support to more adapters in the future.

Run the Sentry init command in your project directory to automatically configure Sentry in your SvelteKit application.

The command guides you through setup and asks which optional Sentry features you want to enable beyond error monitoring.

Copied
npx sentry@latest init
How does sentry init work?

The sentry init command is AI-powered. It analyzes your project and generates a tailored integration, rather than applying a fixed template. Here's what it does:

  • Analyzes your project — reads project files and manifests to understand your SvelteKit app structure, including monorepos. It also respects AI instruction files such as CLAUDE.md, AGENTS.md, and .cursorrules.
  • Detects your framework — identifies SvelteKit and selects the @sentry/sveltekit SDK.
  • Fetches official Sentry docs — uses the current Sentry documentation as the source of truth when generating integration code.
  • Installs dependencies — adds @sentry/sveltekit using your project's package manager.
  • Creates and modifies files — sets up client-side and server-side initialization, SvelteKit hooks or instrumentation, and other selected features based on your SvelteKit version and project structure.
  • Verifies the integration — re-reads modified files after writing to confirm Sentry was integrated.

For full details on what each file does, see the Manual Setup guide.

Prefer the existing SvelteKit wizard?

If you don't want to use the experimental AI-powered flow, run the framework-specific installation wizard instead:

Copied
npx @sentry/wizard@latest -i sveltekit

To configure Sentry manually, follow the Manual Setup guide.

You can prevent ad blockers from blocking Sentry events using tunneling. Use the tunnel option inside your hooks.client.(js|ts) file's Sentry.init to add an API endpoint in your application that forwards Sentry events to Sentry servers.

This will send all events to the tunnel endpoint. However, the events need to be parsed and redirected to Sentry, so you'll need to do additional configuration on the server. You can find a detailed explanation on how to do this on our Troubleshooting page.

hooks.client.(js|ts)
Copied
Sentry.init({
  dsn: "___PUBLIC_DSN___",
tunnel: "/tunnel",
});

By default, the SDK sends user identity data (IP address, ID, and similar) and other data like HTTP bodies and URL query parameters. This will give you rich debugging context.

The SDK always filters sensitive values whose keys match a built-in denylist, such as auth or password, and sends [Filtered] instead.

To send less data, turn off the categories you don't need in the dataCollection option. For the full list of categories and their defaults, see the dataCollection options.

Copied
Sentry.init({
  dsn: "___PUBLIC_DSN___",
dataCollection: { userInfo: false, // other categories
}, });

The sentry init command checks the integration files it creates or modifies before it finishes. To confirm runtime events are reaching Sentry, start your SvelteKit app, exercise the parts of your app that should send events, and then check your Sentry project.

If you used the SvelteKit installation wizard instead, you can also verify your setup with the example page and route it creates:

  1. Open the example page /sentry-example-page in your browser
  2. Click the "Throw Sample Error" button. This triggers two errors:
    • a frontend error
    • an error within the API route

Sentry captures both of these errors for you. Additionally, the button click starts a trace to measure the time it takes for the API request to complete.

Logs (enabled by default)

See structured log entries from your application. You can send logs from anywhere:

Copied
Sentry.logger.info("User action", { userId: "123" });
Sentry.logger.warn("Slow response", { duration: 5000 });
Sentry.logger.error("Operation failed", { reason: "timeout" });

Learn more about Logs configuration.

Application Metrics (enabled by default) NEW

Track and analyze custom application metrics to understand trends and patterns in your app's performance and behavior over time:

Copied
Sentry.metrics.count("checkout.failed", 1);
Sentry.metrics.gauge("queue.depth", 42);
Sentry.metrics.distribution("api_latency", 187, {
  unit: "millisecond",
});

Learn more about Application Metrics.

Now, head over to your project on Sentry.io to view the collected data (it takes a couple of moments for the data to appear).

Need help locating the captured errors in your Sentry project?
  • Open the Issues page and select an error from the issues list to view the full details and context of this error. For more details, see the Issue Details documentation.
  • Open the Traces page and select a trace to reveal more information about each span, its duration, and any errors. For an interactive UI walkthrough, click here.
  • Open the Replays page and select an entry from the list to get a detailed view where you can replay the interaction and get more information to help you troubleshoot.
  • Open the Logs page and filter by service, environment, or search keywords to view log entries from your application. For an interactive UI walkthrough, click here.
  • Open the User Feedback page and click on individual feedback to see more details all in one view. For more information, click here.
  • Open the Application Metrics page to view and analyze your metrics. For more details, see this interactive walkthrough.

At this point, you should have integrated Sentry into your SvelteKit application and should already be sending error and performance data to your Sentry project.

Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:

Are you having problems setting up the SDK?
Was this helpful?
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").