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
ref(sveltekit): Improve manual setup code snippets and structure (#11038)
- streamlined code snippets so that there's only one snippet per file users need to change. Since we can now highlight parts in snippets, I think it's easier for users to identify what they need to change in a file on one glance instead of piecing together two or three snippets.
- Removed TS and JS tabs in the snippets because there's no TS-specific syntax in them.
- Restructured H2 document structure so that not all optional configuration sections are part of "Configuration". This should help users identify what they have to do vs. what's optional and probably not necessary to read.
@@ -24,15 +24,18 @@ If you're updating your Sentry SDK to the latest version, check out our [migrati
24
24
25
25
## Configure
26
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.
28
+
27
29
### Client-side Setup
28
30
29
-
1.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)`.
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)`.
30
32
31
-
2. At the top of your client hooks file, initialize the Sentry SDK as shown in the snippet below. See the [Basic Options](../configuration/options/) page to view other SDK configuration options.
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):
1.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)`.
66
+
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)`.
96
67
97
-
2. At the top of your server hooks file, initialize the Sentry SDK as shown in the snippet below. See the [Basic Options](../configuration/options/) page to view other SDK configuration options.
68
+
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.
69
+
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).
70
+
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).
4. Add the Sentry request handler to the [`handle` hook](https://kit.svelte.dev/docs/hooks#server-hooks-handle).
148
-
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):
@@ -189,7 +115,7 @@ The `sentrySvelteKit()` function adds Vite plugins to your Vite config to:
189
115
- Automatically upload source maps to Sentry
190
116
- Automatically instrument `load` functions for tracing
191
117
192
-
### Configure Source Maps Upload
118
+
### Source Maps Upload
193
119
194
120
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.
Using the `sourceMapsUploadOptions` object is useful if the default source maps upload doesn't work out of the box, for instance, if you have a customized build setup or if you're using the SDK with a SvelteKit adapter other than the [supported adapters](../#compatibility).
259
166
260
167
#### Overriding SvelteKit Adapter detection
261
168
262
169
By default, `sentrySvelteKit` will try to detect your SvelteKit adapter to configure source maps upload correctly.
263
170
If you're not using one of the [supported adapters](../#compatibility) or the wrong one is detected, you can override the adapter detection by passing the `adapter` option to `sentrySvelteKit`:
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.
317
207
318
-
exportdefault {
319
-
plugins: [
320
-
sentrySvelteKit({
321
-
autoUploadSourceMaps: false,
322
-
}),
323
-
sveltekit(),
324
-
],
325
-
// ... rest of your Vite config
326
-
};
327
-
```
208
+
## Optional Configuration
328
209
329
-
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.
210
+
The points explain additional optional configuration or more in-depth customization of your Sentry SvelteKit SDK setup.
330
211
331
212
### Auto-Instrumentation
332
213
@@ -345,25 +226,7 @@ If you have custom Sentry code in these files, you'll have to [manually](#instru
345
226
346
227
By passing the `autoInstrument` option to `sentrySvelteKit` you can disable auto-instrumentation entirely, or customize which `load` functions should be instrumented:
If you set the `autoInstrument` option to `false`, the SDK won't auto-instrument any `load` functions. You can still [manually instrument](#instrument-load-functions-manually) specific `load` functions.
Then, adjust your [SvelteKit CSP configuration](https://kit.svelte.dev/docs/configuration#csp):
439
287
440
-
```javascript {svelte.config.js} {5}
288
+
```javascript {filename: svelte.config.js} {5}
441
289
constconfig= {
442
290
kit: {
443
291
csp: {
@@ -453,7 +301,7 @@ const config = {
453
301
454
302
If you do not want to inject the script responsible for instrumenting client-side `load` calls, you can disable injection by passing `injectFetchProxyScript: false` to `sentryHandle`:
0 commit comments