Skip to content

Commit 5f6e5b5

Browse files
authored
chore(sveltekit): Update README with setup instructions (#7490)
1 parent 873d9bb commit 5f6e5b5

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

packages/sveltekit/README.md

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,105 @@ Currently, the minimum supported version of SvelteKit is `1.0.0`.
2929

3030
This package is a wrapper around `@sentry/node` for the server and `@sentry/svelte` for the client, with added functionality related to SvelteKit.
3131

32-
TODO: Add usage instructions
32+
## Usage
33+
34+
Although the SDK is not yet stable, you're more than welcome to give it a try and provide us with early feedback.
35+
36+
**Here's how to get started:**
37+
38+
1. Ensure you've set up the [`@sveltejs/adapter-node` adapter](https://kit.svelte.dev/docs/adapter-node)
39+
40+
2. Install the Sentry SvelteKit SDK:
41+
42+
```bash
43+
# Using npm
44+
npm install @sentry/sveltekit
45+
46+
# Using yarn
47+
yarn add @sentry/sveltekit
48+
```
49+
50+
3. Create a `sentry.client.config.(js|ts)` file in the root directory of your SvelteKit project.
51+
In this file you can configure the client-side Sentry SDK just like every other browser-based SDK:
52+
53+
```javascript
54+
import * as Sentry from '@sentry/sveltekit';
55+
56+
Sentry.init({
57+
dsn: 'https://[email protected]/4504796902588416',
58+
59+
// For instance, initialize Session Replay:
60+
replaysSessionSampleRate: 0.1,
61+
replaysOnErrorSampleRate: 1.0,
62+
integrations: [new Sentry.Replay()]
63+
});
64+
```
65+
66+
4. Add our `withSentryViteConfig` wrapper around your Vite config so that the Sentry SDK is added to your application in `vite.config.(js|ts)`:
67+
```javascript
68+
import { sveltekit } from '@sveltejs/kit/vite';
69+
import { withSentryViteConfig } from '@sentry/sveltekit';
70+
71+
export default withSentryViteConfig({
72+
plugins: [sveltekit()],
73+
// ...
74+
});
75+
```
76+
77+
5. Create a `sentry.server.config.(js|ts)` file in the root directory of your SvelteKit project.
78+
In this file you can configure the server-side Sentry SDK, like the Sentry Node SDK:
79+
80+
```javascript
81+
import * as Sentry from '@sentry/sveltekit';
82+
83+
Sentry.init({
84+
dsn: 'https://[email protected]/4504796902588416',
85+
});
86+
```
87+
88+
6. To catch errors in your `load` functions in `+page.(js|ts)`, wrap our `wrapLoadWithSentry` function:
89+
90+
```javascript
91+
import { wrapLoadWithSentry } from '@sentry/sveltekit';
92+
93+
export const load = wrapLoadWithSentry((event) => {
94+
//...
95+
});
96+
```
97+
98+
7. In your `hooks.client.(js|ts)` or `hooks.server.(js|ts)`, you can wrap the `handleError` function as follows:
99+
100+
```javascript
101+
import { handleErrorWithSentry } from '@sentry/sveltekit';
102+
import type { HandleClientError } from '@sveltejs/kit';
103+
104+
const myErrorHandler = ((input) => {
105+
console.log('This is the client error handler');
106+
console.log(input.error);
107+
}) satisfies HandleClientError;
108+
109+
export const handleError = handleErrorWithSentry(myErrorHandler);
110+
111+
// or alternatively, if you don't have a custom error handler:
112+
// export const handleError = handleErrorWithSentry();
113+
```
114+
115+
## Known Limitations
116+
117+
This SDK is still under active development and several features are missing.
118+
Take a look at our [SvelteKit SDK Development Roadmap](https://github.com/getsentry/sentry-javascript/issues/6692) to follow the progress:
119+
120+
- **Performance monitoring** is not yet fully supported.
121+
You can add the `BrowserTracing` integration but proper instrumentation for routes, page loads and navigations is still missing.
122+
This will be addressed next, as we release the next alpha builds.
123+
124+
- **Source Maps** upload is not yet working correctly.
125+
We already investigated [some options](https://github.com/getsentry/sentry-javascript/discussions/5838#discussioncomment-4696985) but uploading source maps doesn't work automtatically out of the box yet.
126+
This will be addressed next, as we release the next alpha builds.
127+
128+
- **Adapters** other than `@sveltejs/adapter-node` are currently not supported.
129+
We haven't yet tested other platforms like Vercel.
130+
This is on our roadmap but it will come at a later time.
131+
132+
- We're aiming to **simplify SDK setup** in the future so that you don't have to go in and manually add our wrappers to all your `load` functions and hooks.
133+
This will be addressed once the SDK supports all Sentry features.

0 commit comments

Comments
 (0)