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
<Expandablepermalinktitle="Configure CSP for Client-side `fetch` Instrumentation">
99
+
100
+
<Alert>
101
+
Only relevant for SvelteKit versions below `@sveltejs/[email protected]`
102
+
</Alert>
103
+
If you're using a SvelteKit version older than `sveltejs/[email protected]`, the Sentry SDK injects an inline `<script>` tag into the HTML response of the server.
104
+
This script proxies all client-side `fetch` calls so that `fetch` calls inside your `load` functions are captured by the SDK.
105
+
However, if you configured CSP rules to block inline fetch scripts by default, this script will be [blocked by the browser](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_inline_script).
106
+
107
+
You have multiple options to solve this CSP issue:
108
+
109
+
#### Option 1: Upgrade SvelteKit
110
+
111
+
The easiest option is to update `@sveltejs/kit` to at least version `2.16.0` (or newer). The SDK will not inject the fetch proxy script as it's no longer necessary.
112
+
113
+
#### Option 2: Add Script Hash to CSP policy
114
+
115
+
To enable the script, add an exception for the `sentryHandle` script by adding the hash of the script to your CSP script source rules.
116
+
117
+
If your CSP is defined in `svelte.config.js`, you can add the hash to the `csp.directives.script-src` array:
118
+
119
+
```javascript {filename:svelte.config.js} {5-7}
120
+
constconfig= {
121
+
kit: {
122
+
csp: {
123
+
directives: {
124
+
"script-src": ["sha256-y2WkUILyE4eycy7x+pC0z99aZjTZlWfVwgUAfNc1sY8="], // + rest of your values
125
+
},
126
+
},
127
+
},
128
+
};
129
+
```
130
+
131
+
For external CSP configurations, add the following hash to your `script-src` directive:
We will not change this script any time soon, so the hash will stay consistent.
138
+
</Alert>
139
+
140
+
#### Option 3: Disable `fetch` Proxy Script
141
+
If you don't want to inject the script responsible for instrumenting client-side `fetch` calls, you can disable injection by passing `injectFetchProxyScript: false` to `sentryHandle`:
Note that if you disable the `fetch` proxy script, the SDK will not be able to capture spans for `fetch` calls made by SvelteKit when your route has a server load function. This also means that potential spans created on the server for these `fetch` calls will not be connected to the client-side trace.
<Expandabletitle="Having CSP issues with `fetch` instrumentation on older SvelteKit versions?">
128
+
129
+
If you're using SvelteKit versions older than `2.16.0` and encounter Content Security Policy (CSP) errors related to Sentry's `fetch` instrumentation, you can find support in our [Troubleshooting guide](/platforms/javascript/guides/sveltekit/troubleshooting/#configure-csp-for-client-side-fetch-instrumentation).
130
+
131
+
</Expandable>
132
+
127
133
### Configure Vite
128
134
129
135
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.
@@ -239,60 +245,6 @@ export default {
239
245
};
240
246
```
241
247
242
-
### Configure CSP for Client-side `fetch` Instrumentation
243
-
244
-
<Alert>
245
-
246
-
Only relevant for SvelteKit versions below `@sveltejs/[email protected]`
247
-
248
-
</Alert>
249
-
250
-
If you're using a SvelteKit version older than `sveltejs/[email protected]`, The Sentry SDK injects an inline `<script>` tag into the HTML response of the server.
251
-
This script proxies all client-side `fetch` calls, so that `fetch` calls inside your `load` functions are captured by the SDK.
252
-
However, if you configured CSP rules to block inline fetch scripts by default, this script will be [blocked by the browser](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_inline_script).
253
-
254
-
You have multiple options to solve this CSP issue:
255
-
256
-
#### Upgrade SvelteKit
257
-
258
-
The easiest option is to update `@sveltejs/kit` to at least version `2.16.0` (or newer). The SDK will not inject the fetch proxy script as it's no longer necessary.
259
-
260
-
#### Add Script Hash to CSP policy
261
-
262
-
To enable the script, add an exception for the `sentryHandle` script by adding the hash of the script to your CSP script source rules.
263
-
264
-
If your CSP is defined in `svelte.config.js`, you can add the hash to the `csp.directives.script-src` array:
265
-
266
-
```javascript {filename:svelte.config.js} {5-7}
267
-
constconfig= {
268
-
kit: {
269
-
csp: {
270
-
directives: {
271
-
"script-src": ["sha256-y2WkUILyE4eycy7x+pC0z99aZjTZlWfVwgUAfNc1sY8="], // + rest of your values
272
-
},
273
-
},
274
-
},
275
-
};
276
-
```
277
-
278
-
For external CSP configurations, add the following hash to your `script-src` directive:
We will not make changes to this script any time soon, so the hash will stay consistent.
285
-
286
-
#### Disable `fetch` Proxy Script
287
-
288
-
If you don't want to inject the script responsible for instrumenting client-side `fetch` calls, you can disable injection by passing `injectFetchProxyScript: false` to `sentryHandle`:
Note that if you disable the `fetch` proxy script, the SDK will not be able to capture spans for `fetch` calls made by SvelteKit when your route has a server load function. This also means that potential spans created on the server for these `fetch` calls will not be connected to the client-side trace.
295
-
296
248
### Manual Instrumentation
297
249
298
250
Instead or in addition to [Auto Instrumentation](#auto-instrumentation), you can manually instrument certain SvelteKit-specific features with the SDK:
0 commit comments