8000 doc(sveltekit): Update README (#7653) · TrySound/sentry-javascript@6678a4a · GitHub
[go: up one dir, main page]

Skip to content

Commit 6678a4a

Browse files
authored
doc(sveltekit): Update README (getsentry#7653)
1 parent a3dfde6 commit 6678a4a

File tree

1 file changed

+49
-30
lines changed

1 file changed

+49
-30
lines changed

packages/sveltekit/README.md

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ TODO: No docs yet, comment back in once we have docs
1919

2020
## SDK Status
2121

22-
This SDK is currently in **Alpha state** and we're still experimenting with APIs and functionality. We therefore make no guarantees in terms of semver or breaking changes. If you want to try this SDK and come across a problem, please open a [GitHub Issue](https://github.com/getsentry/sentry-javascript/issues/new/choose).
22+
This SDK is currently in **Alpha state** and we're still experimenting with APIs and functionality.
23+
We therefore make no guarantees in terms of semver or breaking changes.
24+
If you want to try this SDK and come across a problem, please open a [GitHub Issue](https://github.com/getsentry/sentry-javascript/issues/new/choose).
2325

2426
## Compatibility
2527

2628
Currently, the minimum supported version of SvelteKit is `1.0.0`.
2729

2830
## General
2931

30-
This package is a wrapper around `@sentry/node` for the server and `@sentry/svelte` for the client, with added functionality related to SvelteKit.
32+
This package is a wrapper around `@sentry/node` for the server and `@sentry/svelte` for the client side, with added functionality related to SvelteKit.
3133

3234
## Usage
3335

@@ -55,72 +57,89 @@ Although the SDK is not yet stable, you're more than welcome to give it a try an
5557

5658
Sentry.init({
5759
dsn: '__DSN__',
58-
60+
traceSampleRate: 1.0,
5961
// For instance, initialize Session Replay:
6062
replaysSessionSampleRate: 0.1,
6163
replaysOnErrorSampleRate: 1.0,
6264
integrations: [new Sentry.Replay()]
6365
});
6466
```
6567

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-
```
7668

77-
5. Create a `sentry.server.config.(js|ts)` file in the root directory of your SvelteKit project.
69+
4. Create a `sentry.server.config.(js|ts)` file in the root directory of your SvelteKit project.
7870
In this file you can configure the server-side Sentry SDK, like the Sentry Node SDK:
7971

8072
```javascript
8173
import * as Sentry from '@sentry/sveltekit';
8274

8375
Sentry.init({
8476
dsn: '__DSN__',
77+
traceSampleRate: 1.0,
8578
});
8679
```
8780

88-
6. To catch errors in your `load` functions in `+page.(js|ts)`, wrap our `wrapLoadWithSentry` function:
89-
81+
5. Add our `withSentryViteConfig` wrapper around your Vite config so that the Sentry SDK is added to your application in `vite.config.(js|ts)`:
9082
```javascript
91-
import { wrapLoadWithSentry } from '@sentry/sveltekit';
83+
import { sveltekit } from '@sveltejs/kit/vite';
84+
import { withSentryViteConfig } from '@sentry/sveltekit';
9285

93-
export const load = wrapLoadWithSentry((event) => {
94-
//...
86+
export default withSentryViteConfig({
87+
plugins: [sveltekit()],
88+
// ...
9589
});
9690
```
9791

98-
7. In your `hooks.client.(js|ts)` or `hooks.server.(js|ts)`, you can wrap the `handleError` function as follows:
92+
6. In your `hooks.client.(js|ts)` or `hooks.server.(js|ts)`, wrap the `handleError` functions as follows:
9993

10094
```javascript
10195
import { handleErrorWithSentry } from '@sentry/sveltekit';
102-
import type { HandleClientError } from '@sveltejs/kit';
10396

10497
const myErrorHandler = ((input) => {
105-
console.log('This is the client error handler');
106-
console.log(input.error);
107-
}) satisfies HandleClientError;
98+
console.error('An error occurred on the client-side');
99+
return error;
100+
});
108101

109102
export const handleError = handleErrorWithSentry(myErrorHandler);
110-
111103
// or alternatively, if you don't have a custom error handler:
112104
// export const handleError = handleErrorWithSentry();
113105
```
114106

107+
7. To capture performance data on the server-side, add our handler to the `handle` hook in `hooks.server.ts`:
108+
109+
```javascript
110+
import { sentryHandle } from '@sentry/sveltekit';
111+
112+
export const handle = sentryHandle;
113+
// or alternatively, if you already have a handler defined, use the `sequence` function
114+
// see: https://kit.svelte.dev/docs/modules#sveltejs-kit-hooks-sequence
115+
// export const handle = sequence(sentryHandle, yourHandler);
116+
```
117+
118+
8. To catch errors and performance data in your universal `load` functions (e.g. in `+page.(js|ts)`), wrap our `wrapLoadWithSentry` function around your load code:
119+
120+
```javascript
121+
import { wrapLoadWithSentry } from '@sentry/sveltekit';
122+
123+
export const load = wrapLoadWithSentry((event) => {
124+
//... your load code
125+
});
126+
```
127+
128+
9. To catch errors and performance data in your server `load` functions (e.g. in `+page.server.(js|ts)`), wrap our `wrapServerLoadWithSentry` function around your load code:
129+
130+
```javascript
131+
import { wrapServerLoadWithSentry } from '@sentry/sveltekit';
132+
133+
export const load = wrapServerLoadWithSentry((event) => {
134+
//... your server load code
135+
});
136+
```
137+
115138
## Known Limitations
116139

117140
This SDK is still under active development and several features are missing.
118141
Take a look at our [SvelteKit SDK Development Roadmap](https://github.com/getsentry/sentry-javascript/issues/6692) to follow the progress:
119142

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-
124143
- **Source Maps** upload is not yet working correctly.
125144
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.
126145
This will be addressed next, as we release the next alpha builds.
@@ -129,5 +148,5 @@ Take a look at our [SvelteKit SDK Development Roadmap](https://github.com/getsen
129148
We haven't yet tested other platforms like Vercel.
130149
This is on our roadmap but it will come at a later time.
131150

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.
151+
- 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.
133152
This will be addressed once the SDK supports all Sentry features.

0 commit comments

Comments
 (0)
0