Skip to content

Commit 00b2c3e

Browse files
committed
rework SvelteKit manual setup page into quick start guide
1 parent 6dcd79d commit 00b2c3e

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

docs/platforms/javascript/guides/sveltekit/manual-setup.mdx

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,26 @@ description: "Learn how to manually set up Sentry in your SvelteKit app and capt
99
installer](/platforms/javascript/guides/sveltekit).
1010
</Alert>
1111

12-
<PlatformContent includePath="getting-started-prerequisites" />
12+
## Prerequisites
13+
14+
You need:
15+
16+
- A Sentry [account](https://sentry.io/signup/) and [project](/product/projects/)
17+
- Your application up and running
18+
19+
<Expandable title="Notes on SvelteKit adapter compatibility">
20+
The SvelteKit Sentry SDK is designed to work out of the box with the following SvelteKit adapters:
21+
22+
- [Adapter-auto](https://kit.svelte.dev/docs/adapter-auto) – for Vercel; other platforms might work but we don't guarantee compatibility at this time
23+
- [Adapter-vercel](https://kit.svelte.dev/docs/adapter-vercel) – only for Node (Lambda) runtimes, not yet Vercel's edge runtime
24+
- [Adapter-cloudflare](https://kit.svelte.dev/docs/adapter-cloudflare) – supported but requires [additional setup](https://docs.sentry.io/platforms/javascript/guides/cloudflare/frameworks/sveltekit/)
25+
- [Adapter-node](https://kit.svelte.dev/docs/adapter-node)
26+
27+
Other adapters may work but aren't currently supported. We're looking into extending first-class support to more adapters in the future.
28+
29+
Also, Sentry's SvelteKit SDK does not yet work with all non-node server runtimes, such as Vercel's edge runtime.
30+
31+
</Expandable>
1332

1433
## Step 1: Install
1534

@@ -45,7 +64,7 @@ You need to initialize and configure the Sentry SDK in three places: the client
4564

4665
### Configure Client-side Sentry
4766

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).
67+
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 and add the `handleErrorWithSentry` function to the [`handleError` hook](https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError).
4968

5069
```javascript {filename:hooks.client.(js|ts)} {1, 3-28, 34}
5170
import * as Sentry from "@sentry/sveltekit";
@@ -89,7 +108,7 @@ export const handleError = Sentry.handleErrorWithSentry(myErrorHandler);
89108

90109
### Configure Server-side Sentry
91110

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).
111+
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 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).
93112

94113
```javascript {filename:hooks.server.(js|ts)} {1, 3-18, 24, 28}
95114
import * as Sentry from "@sentry/sveltekit";
@@ -411,11 +430,11 @@ Follow this guide to [configure Sentry for Cloudflare](/platforms/javascript/gui
411430

412431
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.
413432

414-
Update `Sentry.init` file with the following options:
433+
Update `Sentry.init` in your `hooks.client.(js|ts)` file with the following option:
415434

416-
```javascript
435+
```javascript {filename:hooks.client.(js|ts)}
417436
Sentry.init({
418-
dsn: "https://[email protected]/0",
437+
dsn: "___PUBLIC_DSN___",,
419438
tunnel: "/tunnel",
420439
});
421440
```
@@ -428,9 +447,9 @@ Let's test your setup and confirm that Sentry is working correctly and sending d
428447

429448
### Issues
430449

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:
450+
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:
432451

433-
```javascript
452+
```javascript {filename:+page.svelte}
434453
<button
435454
type="button"
436455
onclick={() => {
@@ -452,15 +471,15 @@ To verify that Sentry captures errors and creates issues in your Sentry project,
452471
### Tracing
453472
To test tracing, create a test API route like `src/routes/sentry-example/+server.(js|ts)`:
454473

455-
```javascript
474+
```javascript {filename:+server.(js|ts)}
456475
export const GET = async () => {
457476
throw new Error("Sentry Example API Route Error");
458477
};
459478
```
460479

461480
Next, update your test button to call this route and throw an error if the response isn't `ok`:
462481

463-
```javascript
482+
```javascript {filename:+page.svelte}
464483
<script>
465484
import * as Sentry from '@sentry/sveltekit';
466485

0 commit comments

Comments
 (0)