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
docs(js): Rework SvelteKit manual setup into quick start guide (#13632)
<!-- Use this checklist to make sure your PR is ready for merge. You may
delete any sections you don't need. -->
## DESCRIBE YOUR PR
We've reworked the Manual Setup page for SvelteKit into a Quick Start
guide.
This page covers many in-depth topics that should be handled on other
pages of the SvelteKit documentation. We will update and move this
content in a follow-up issue/PR.
This affects the following content:
- "Source Maps Upload"
- everything in "Step3: Optional Configuration"
Closes: #13399
## IS YOUR CHANGE URGENT?
Help us prioritize incoming PRs by letting us know when the change needs
to go live.
- [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [x] None: Not urgent, can wait up to 1 week+
## SLA
- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
added an urgent due date to it.
Thanks in advance for your help!
## PRE-MERGE CHECKLIST
*Make sure you've checked the following before merging your changes:*
- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)
## EXTRA RESOURCES
- [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
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
42
+
## Step 2: Configure
26
43
27
-
The Sentry SDK needs to be initialized and configured in three places: On the client-side, server-side and in your Vite config.
44
+
You need to initialize and configure the Sentry SDK in three places: the clientside, the serverside, and your Vite config.
28
45
29
-
### Client-side Setup
46
+
### Configure Client-Side Sentry
30
47
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)`.
48
+
Create a client hooks file `src/hooks.client.(js|ts)` in the `src` folder of your project if you don't have one already. In this file, import and initialize the Sentry SDK and add the `handleErrorWithSentry` function to the [`handleError` hook](https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError).
32
49
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):
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)`.
90
+
### Configure Server-Side Sentry
69
91
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).
92
+
Create a server hooks file `src/hooks.server.(js|ts)` in the `src` folder of your project if you don't have one already. In this file, import and initialize the Sentry SDK and add the `handleErrorWithSentry` function to the [`handleError` hook](https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError) and the Sentry request handler to the [`handle` hook](https://kit.svelte.dev/docs/hooks#server-hooks-handle).
Add the `sentrySvelteKit` plugins to your `vite.config.(js|ts)` file so the Sentry SDK can apply build-time features.
105
-
Make sure that it is added _before_ the sveltekit plugin:
129
+
Add the `sentrySvelteKit` plugin **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
142
### Source Maps Upload
123
143
124
144
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 +227,7 @@ export default {
207
227
208
228
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
229
210
-
## Optional Configuration
230
+
## Step 3: Optional Configuration
211
231
212
232
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
402
Follow this guide to [configure Sentry for Cloudflare](/platforms/javascript/guides/cloudflare/frameworks/sveltekit/).
403
+
404
+
## Step 5: Avoid Ad Blockers With Tunneling (Optional)
405
+
406
+
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.
407
+
408
+
Update `Sentry.init` in your `hooks.client.(js|ts)` file with the following option:
409
+
410
+
```javascript {filename:hooks.client.(js|ts)}
411
+
Sentry.init({
412
+
dsn:"___PUBLIC_DSN___",,
413
+
tunnel:"/tunnel",
414
+
});
415
+
```
416
+
417
+
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).
418
+
419
+
## Step 6: Verify Your Setup
420
+
421
+
Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.
422
+
423
+
### Issues
424
+
425
+
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 that throws an error when clicked:
Other adapters may work but aren't currently supported. We're looking into extending first-class support to more adapters in the future.
19
-
20
-
Also, Sentry's SvelteKit SDK does not yet work with all non-node server runtimes, such as Vercel's edge runtime.
14
+
-**Fully supported Node.js runtimes**
15
+
-[Adapter-auto](https://kit.svelte.dev/docs/adapter-auto) for Vercel; other Node.js-based platforms might work, but we don't guarantee compatibility at this time
16
+
-[Adapter-vercel](https://kit.svelte.dev/docs/adapter-vercel) when used with Vercel's Node.js Lambda runtime
- Non-Node.js server runtimes, such as Vercel's edge runtime, are not yet supported.
22
+
-**Other adapters**
23
+
- 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.
0 commit comments