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">
98
+
<Expandablepermalinktitle="Configure CSP for Client-side `fetch` Instrumentation">
99
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).
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
106
107
-
You have multiple options to solve this CSP issue:
107
+
You have multiple options to solve this CSP issue:
108
108
109
-
#### Option 1: Upgrade SvelteKit
109
+
#### Option 1: Upgrade SvelteKit
110
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.
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
112
113
-
#### Option 2: Add Script Hash to CSP policy
113
+
#### Option 2: Add Script Hash to CSP policy
114
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.
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
116
117
-
If your CSP is defined in `svelte.config.js`, you can add the hash to the `csp.directives.script-src` array:
117
+
If your CSP is defined in `svelte.config.js`, you can add the hash to the `csp.directives.script-src` array:
118
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
-
```
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
130
131
-
For external CSP configurations, add the following hash to your `script-src` directive:
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
139
+
consistent.
140
+
</Alert>
139
141
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`:
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`:
146
145
147
-
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.
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.
Copy file name to clipboardExpand all lines: platform-includes/sourcemaps/upload/primer/javascript.sveltekit.mdx
+18-9Lines changed: 18 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,27 @@
1
1
### Source Maps Upload
2
2
3
-
By default, `sentrySvelteKit()`will add an instance of the 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.
3
+
By default, the `sentrySvelteKit()` Vite plugin uploads 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.
4
4
5
5
However, you still need to specify your Sentry auth token as well as your org and project slugs.
6
6
There are two ways to set them:
7
7
8
8
**Option 1**
9
9
10
-
You can set them as environment variables, for example, in a `.env` file:
10
+
You can set all values as environment variables, for example, in a `.env` file:
11
11
12
-
-`SENTRY_ORG` your Sentry org slug
13
-
-`SENTRY_PROJECT` your Sentry project slug
14
-
-`SENTRY_AUTH_TOKEN` your Sentry auth token (can be obtained from the [Organization Token Settings](https://sentry.io/orgredirect/organizations/:orgslug/settings/auth-tokens/))
15
-
-`SENTRY_URL` your Sentry instance URL. This is only required if you use your own Sentry instance (as opposed to `https://sentry.io`).
12
+
```bash {filename: .env}
13
+
# DO NOT commit this file to your repo. The auth token is a secret.
14
+
SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
15
+
SENTRY_ORG=___ORG_SLUG___
16
+
SENTRY_PROJECT=___PROJECT_SLUG___
17
+
# SENTRY_URL is only necessary if you're using a self-hosted Sentry
18
+
# instance (as opposed to `https://sentry.io`)
19
+
SENTRY_URL="https://your-sentry-instance.com"
20
+
```
16
21
17
-
**Option 2:**
22
+
**Option 2**
18
23
19
-
You can also set them by passing a `sourceMapsUploadOptions` object to `sentrySvelteKit`, as seen in the example below. For a full list of available options, see the [Sentry Vite Plugin documentation](https://www.npmjs.com/package/@sentry/vite-plugin#options).
24
+
You can also set your org and project slugs by passing a `sourceMapsUploadOptions` object to `sentrySvelteKit`, as seen in the example below. For a full list of available options, see the [Sentry Vite Plugin documentation](https://www.npmjs.com/package/@sentry/vite-plugin#options).
20
25
21
26
<OrgAuthTokenNote />
22
27
@@ -30,7 +35,7 @@ export default {
30
35
sourceMapsUploadOptions: {
31
36
org:"___ORG_SLUG___",
32
37
project:"___PROJECT_SLUG___",
33
-
authToken:"___ORG_AUTH_TOKEN___",
38
+
authToken:"process.env.SENTRY_AUTH_TOKEN",
34
39
// If you're self-hosting Sentry, also add your instance URL:
35
40
// url: "https://your-self-hosted-sentry.com/",
36
41
},
@@ -41,6 +46,10 @@ export default {
41
46
};
42
47
```
43
48
49
+
<Alertlevel="warning"title="Important">
50
+
To keep your auth token secure, always store it in an environment variable
51
+
instead of directly in your files.
52
+
</Alert>
44
53
### Override SvelteKit Adapter Detection
45
54
46
55
By default, `sentrySvelteKit` will try to detect your SvelteKit adapter to configure the source maps upload correctly. If you're not using one of the [supported adapters](/platforms/javascript/guides/sveltekit) or the wrong one is detected, you can override the adapter detection by passing the `adapter` option to `sentrySvelteKit`:
0 commit comments