You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Learn how to manually set up Sentry in your Angular app and capture your first errors."
4
+
description: "Learn how to manually set up Sentry in your SvelteKit app and capture your first errors."
5
5
---
6
6
7
-
If you can't (or prefer not to) run the <PlatformLinkto="/#install">automatic setup</PlatformLink>, you can follow the instructions below to configure the Sentry SvelteKit SDK in your application. This guide is also useful to adjust the pre-set configuration if you used the installation wizard for automatic setup.
7
+
<Alerttype="info">
8
+
For the fastest setup, we recommend using the [wizard
Run the command for your preferred package manager to add the Sentry SDK to your application:
10
27
11
28
```bash {tabTitle:npm}
12
29
npm install @sentry/sveltekit --save
@@ -22,18 +39,15 @@ pnpm add @sentry/sveltekit
22
39
23
40
If you're updating your Sentry SDK to the latest version, check out our [migration guide](https://github.com/getsentry/sentry-javascript/blob/master/MIGRATION.md) to learn more about breaking changes.
24
41
25
-
## Configure
26
-
27
-
The Sentry SDK needs to be initialized and configured in three places: On the client-side, server-side and in your Vite config.
42
+
## Step 2: Configure
28
43
29
-
### Client-side Setup
44
+
You need to initialize and configure the Sentry SDK in three places: the client side, the server side, and your Vite config.
30
45
31
-
If you don't already have a [client hooks](https://kit.svelte.dev/docs/hooks#shared-hooks) file, create a new one in `src/hooks.client.(js|ts)`.
46
+
### Configure Client-side Sentry
32
47
33
-
At the top of your client hooks file, import and initialize the Sentry SDK as shown in the snippet below. See the [Basic Options](../configuration/options/) page to view other SDK configuration options.
34
-
Also, add the `handleErrorWithSentry` function to the [`handleError` hook](https://kit.svelte.dev/docs/hooks#shared-hooks-handleerror):
48
+
Create a client hooks file `src/hooks.client.(js|ts)` if you don't have one already. In this file, import and initialize the Sentry SDK, specifying any SDK options for the client. Add the `handleErrorWithSentry` function to the [`handleError` hook](https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError).
If you don't already have a [server hooks](https://kit.svelte.dev/docs/hooks#server-hooks) file, create a new one in `src/hooks.server.(js|ts)`.
92
+
Create a server hooks file `src/hooks.server.(js|ts)` if you don't have one already. In this file, import and initialize the Sentry SDK, specifying any SDK options for the client. Additionally, add the `handleErrorWithSentry` function to the [`handleError` hook](https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError) and add the Sentry request handler to the [`handle` hook](https://kit.svelte.dev/docs/hooks#server-hooks-handle).
69
93
70
-
At the top of your server hooks file, import and initialize the Sentry SDK as shown in the snippet below. See the [Basic Options](../configuration/options/) page to view other SDK configuration options.
71
-
Add the `handleErrorWithSentry` function to the [`handleError` hook](https://kit.svelte.dev/docs/hooks#shared-hooks-handleerror) and add the Sentry request handler to the [`handle` hook](https://kit.svelte.dev/docs/hooks#server-hooks-handle).
72
-
If you're already using your own handler(s), use SvelteKit's [`sequence`](https://kit.svelte.dev/docs/modules#sveltejs-kit-hooks-sequence) function to add the Sentry handler _before_ your handler(s).
Add `sentrySvelteKit` to your plugins before `sveltekit` in your `vite.config.(js|ts)` file to automatically upload source maps to Sentry and instrument `load` functions for tracing if it's configured.
The `sentrySvelteKit()` function adds Vite plugins to your Vite config to:
118
-
119
-
- Automatically upload source maps to Sentry
120
-
- Automatically instrument `load` functions for tracing
121
-
122
148
### Source Maps Upload
123
149
124
150
By default, `sentrySvelteKit()` will add an instance of the [Sentry Vite Plugin](https://www.npmjs.com/package/@sentry/vite-plugin), to upload source maps for both server and client builds. This means that when you run a production build (`npm run build`), source maps will be generated and uploaded to Sentry, so that you get readable stack traces in your Sentry issues.
@@ -207,7 +233,7 @@ export default {
207
233
208
234
If you disable automatic source maps upload, you must explicitly set a `release` value in your `Sentry.init()` configs. You can also skip the `sentry-cli` configuration step below.
209
235
210
-
## Optional Configuration
236
+
## Step 3: Optional Configuration
211
237
212
238
The points explain additional optional configuration or more in-depth customization of your Sentry SvelteKit SDK setup.
If you're deploying your application to Cloudflare Pages, you need to adjust your server-side setup.
382
408
Follow this guide to [configure Sentry for Cloudflare](/platforms/javascript/guides/cloudflare/frameworks/sveltekit/).
409
+
410
+
## Step 5: Avoid Ad Blockers With Tunneling (Optional)
411
+
412
+
You can prevent ad blockers from blocking Sentry events using tunneling. Use the `tunnel` option to add an API endpoint in your application that forwards Sentry events to Sentry servers.
413
+
414
+
Update `Sentry.init` file with the following options:
This will send all events to the `tunnel` endpoint. However, the events need to be parsed and redirected to Sentry, so you need to do additional configuration on the server. You can find a detailed explanation on how to do this on our [Troubleshooting page](/platforms/javascript/guides/sveltekit/troubleshooting/#using-the-tunnel-option).
424
+
425
+
## Step 6: Verify Your Setup
426
+
427
+
Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.
428
+
429
+
### Issues
430
+
431
+
To verify that Sentry captures errors and creates issues in your Sentry project, create a test page, for example at `src/routes/sentry-example/+page.svelte` with a button:
0 commit comments