Repository navigation
SvelteKit Support #5838
Replies: 20 comments 81 replies
|
I would like a lot the aforementioned SvelteKit support :) Until then, do you have a small quick-n-dirty howto to get it running economy class style? |
|
Would be great to have SvelteKit support! |
|
SvelteKit is in release candidate phase for 1.0. Once this is out, and stable, I think it is fair for us/Sentry to consider providing first class support. So we would just need to define what that is exactly. Should it work through the node package, similar to NextJS?
These are all with a question mark. Curious what would be the most important/most valuable for Svelte devs to see in Sentry |
|
I was also wondering atleast a small guide to enable sourcemaps & a clean client + server setup for sveltekit. Hopefully I'll make one if I get some time in the coming weeks. |
|
For those who are following this issue and need help with sourcemaps, we recently revamped our support here. We now have bundler plugins for https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/ |
|
SvelteKit 1.0 has been announced! |
|
Hey folks, I had some time over the holidays and managed to come up with some first strategies on how to use the current Sentry SDKs for SvelteKit. So here are some instructions on how to get started. DisclaimerPlease keep in mind that this is not yet complete and that there's no guarantee that this works in every situation. There are probably some things we could do better here, so please feel free to share your experiences. Also, I've only used what's publicly available, so this is not a new SDK something that goes into this direction. Get StartedInstall the Svelte and Node SDKs: npm install --save @sentry/svelte @sentry/nodeInitializing the SDKsHere, one of the challenges is to initialize the SDK as early as possible, both on client and server. The best I came up with was to leverage SvelteKit's hooks, to initialize the SDKs and catch errors: Server-sideHere we can initialize the Node SDK for the server side:
import * as SentryNode from '@sentry/node';
import '@sentry/tracing';
SentryNode.init({
dsn: '__DSN__',
tracesSampleRate: 1.0,
// Add the Http integration for tracing
integrations: [new SentryNode.Integrations.Http()]
});
SentryNode.setTag('svelteKit', 'server');
// use handleError to report errors during server-side data loading
export const handleError = (({ error, event }) => {
SentryNode.captureException(error, { contexts: { sveltekit: { event } } });
return {
message: error.message,
};
}) satisfies HandleServerError;Client-sideHere we can intialize the Svelte SDK which will only run on the client: import * as SentrySvelte from '@sentry/svelte';
import { BrowserTracing } from '@sentry/tracing';
SentrySvelte.init({
dsn: '__DSN__',
integrations: [new BrowserTracing()],
tracesSampleRate: 1.0,
});
SentrySvelte.setTag('svelteKit', 'browser');
// This will catch errors in `load` functions from `+page.ts` files
export const handleError = (({ error, event }) => {
SentrySvelte.captureException(error, { contexts: { sveltekit: { event } } });
return {
message: error.message
};
}) satisfies HandleClientError;LimitationsThis should give you error monitoring in most situations. However, source maps are currently not yet working correctly. I didn't have time to look into this, yet but the high-level plan would be to configure Vite to generate source maps, which should then be uploaded to Sentry. For this, You can use the Sentry Vite Plugin. @ambiguous48 already posted some hints what might be necessary for this to work. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Update: The Sentry SvelteKit SDK has been released!
Hey! Sentry has released a Svelte SDK, but the SDK doesn't have first class support for SvelteKit. If you would like to see this happen, please leave a comment/reaction to this post!
Svelte SDK: https://www.npmjs.com/package/@sentry/svelte
Svelte SDK Initial Roadmap: #5492
Coming Soon Page for SvelteKit
TLDR: Below how to set up with Svelte and Node SDKs
All reactions