-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
chore(sveltekit): Update README
with setup instructions
#7490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,105 @@ Currently, the minimum supported version of SvelteKit is `1.0.0`. | |
|
||
This package is a wrapper around `@sentry/node` for the server and `@sentry/svelte` for the client, with added functionality related to SvelteKit. | ||
|
||
TODO: Add usage instructions | ||
## Usage | ||
|
||
Although the SDK is not yet stable, you're more than welcome to give it a try and provide us some early feedback. | ||
|
||
**Here's how to get started:** | ||
|
||
1. Ensure you've set up the [`@sveltejs/adapter-node` adapter](https://kit.svelte.dev/docs/adapter-node) | ||
|
||
2. Install the Sentry SvelteKit SDK: | ||
|
||
```bash | ||
# Using npm | ||
npm install @sentry/sveltekit | ||
|
||
# Using yarn | ||
yarn add @sentry/sveltekit | ||
``` | ||
|
||
3. Create a `sentry.client.config.(js|ts)` file in the root directory of your SvelteKit project. | ||
In this file you can configure the client-side Sentry SDK just like every other browser-based SDK: | ||
|
||
```javascript | ||
import * as Sentry from '@sentry/sveltekit'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/4504796902588416', | ||
|
||
// For instance, initialize Session Replay: | ||
replaysSessionSampleRate: 0.1, | ||
replaysOnErrorSampleRate: 1.0, | ||
integrations: [new Sentry.Replay()] | ||
}); | ||
``` | ||
|
||
4. Add our `withSentryViteConfig` wrapper around your Vite config so that the Sentry SDK is added to your application in `vite.config.(js|ts)`: | ||
```javascript | ||
import { sveltekit } from '@sveltejs/kit/vite'; | ||
import { withSentryViteConfig } from '@sentry/sveltekit'; | ||
|
||
export default withSentryViteConfig({ | ||
plugins: [sveltekit()], | ||
// ... | ||
}); | ||
``` | ||
|
||
5. Create a `sentry.server.config.(js|ts)` file in the root directory of your SvelteKit project. | ||
In this file you can configure the server-side Sentry SDK, like the Sentry Node SDK: | ||
|
||
```javascript | ||
import * as Sentry from '@sentry/sveltekit'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/4504796902588416', | ||
}); | ||
``` | ||
|
||
6. To catch errors in your `load` functions in `+page.(js|ts)`, wrap our `wrapLoadWithSentry` function: | ||
|
||
```javascript | ||
import { wrapLoadWithSentry } from '@sentry/sveltekit'; | ||
|
||
export const load = wrapLoadWithSentry((event) => { | ||
//... | ||
}); | ||
``` | ||
|
||
7. In your `hooks.client.(js|ts)` or `hooks.server.(js|ts)`, you can wrap the `handleError` function as follows: | ||
|
||
```javascript | ||
import { handleErrorWithSentry } from '@sentry/sveltekit'; | ||
import type { HandleClientError } from '@sveltejs/kit'; | ||
|
||
const myErrorHandler = ((input) => { | ||
console.log('This is the client error handler'); | ||
console.log(input.error); | ||
}) satisfies HandleClientError; | ||
|
||
export const handleError = handleErrorWithSentry(myErrorHandler); | ||
|
||
// or alternatively, if you don't have a custom error handler: | ||
// export const handleError = handleErrorWithSentry(); | ||
``` | ||
|
||
## Known Limitations | ||
|
||
This SDK is still under active development and several features are missing. | ||
Take a look at our [SvelteKit SDK Development Roadmap](https://github.com/getsentry/sentry-javascript/issues/6692) to follow the progress: | ||
|
||
- **Performance monitoring** is not yet fully supported. | ||
You can add the `BrowserTracing` integration but proper instrumentation for routes, page loads and navigations is still missing. | ||
This will be addressed next, as we release the next alpha builds. | ||
|
||
- **Source Maps** upload is not yet working correctly. | ||
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. | ||
This will be addressed next, as we release the next alpha builds. | ||
|
||
- **Adapters** other than `@sveltejs/adapter-node` are currently not supported. | ||
We haven't yet tested other platforms like Vercel. | ||
This is on our roadmap but it will come at a later time. | ||
|
||
- 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. | ||
This will be addressed once the SDK supports all Sentry features. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.