Skip to content

feat(sveltekit): Add wrapper for server load function - #7416

Merged
AbhiPrasad merged 6 commits into
developfrom
abhi-sveltekit-server-load-error
Mar 14, 2023
Merged

feat(sveltekit): Add wrapper for server load function#7416
AbhiPrasad merged 6 commits into
developfrom
abhi-sveltekit-server-load-error

Conversation

@AbhiPrasad

@AbhiPrasadAbhiPrasad commented Mar 10, 2023

Copy link
Copy Markdown
Contributor

closes#7403

Add wrapper for server-side load function.

Also went ahead and fixed the mechanism type to be instrument, since sveltekit is not an accepted value. Nvm I misunderstood, changed this decision.

Using Proxy for this which I assume is fine, but we can avoid using it if needed

Usage:

src/routes/blog/[slug]/+layout.server.js

import*asdbfrom'$lib/server/database';/** @type {import('./$types').LayoutServerLoad} */asyncfunctioncustomLoad(){return{posts: awaitdb.getPostSummaries()};}exportconstload=wrapLoadWithSentry(customLoad);

We also special case errors coming from the SvelteKit error helper.

If users defined a load function like so:

import{error}from'@sveltejs/kit';import*asdbfrom'$lib/server/database';/** @type {import('./$types').PageServerLoad} */exportasyncfunctionload({ params }){constpost=awaitdb.getPost(params.slug);if(!post){throwerror(404,{message: 'Not found'});}return{ post };}

We would not capture that thrown error as it is a 404. In the future we can provide a way to opt-in to 4xx errors.

@github-actions

github-actionsBot commented Mar 10, 2023

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
@sentry/browser - ES5 CDN Bundle (gzipped + minified)20.39 KB (-0.05% 🔽)
@sentry/browser - ES5 CDN Bundle (minified)63.24 KB (-0.05% 🔽)
@sentry/browser - ES6 CDN Bundle (gzipped + minified)18.96 KB (-0.09% 🔽)
@sentry/browser - ES6 CDN Bundle (minified)56.15 KB (-0.06% 🔽)
@sentry/browser - Webpack (gzipped + minified)20.63 KB (-0.06% 🔽)
@sentry/browser - Webpack (minified)67.38 KB (-0.05% 🔽)
@sentry/react - Webpack (gzipped + minified)20.65 KB (-0.06% 🔽)
@sentry/nextjs Client - Webpack (gzipped + minified)52.05 KB (-0.02% 🔽)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified)33.63 KB (-0.03% 🔽)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified)25.98 KB (-0.07% 🔽)
@sentry/replay ES6 CDN Bundle (gzipped + minified)43.18 KB (+0.01% 🔺)
@sentry/replay - Webpack (gzipped + minified)37.19 KB (0%)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified)61.28 KB (-0.03% 🔽)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified)54.36 KB (-0.03% 🔽)

@AbhiPrasad
AbhiPrasadforce-pushed the abhi-sveltekit-server-load-error branch from b2db998 to e4aa3f4CompareMarch 13, 2023 09:58
@AbhiPrasad
AbhiPrasadforce-pushed the abhi-sveltekit-server-load-error branch from e4aa3f4 to afddce3CompareMarch 13, 2023 16:17
@AbhiPrasad
AbhiPrasad requested review from Lms24 and mydeaMarch 13, 2023 16:19
@AbhiPrasad
AbhiPrasad marked this pull request as ready for review March 13, 2023 16:19
return new Proxy(origLoad, {
apply: async (wrappingTarget, thisArg, args: Parameters<ServerLoad>) => {
try {
return await wrappingTarget.apply(thisArg, args);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we do the same here as we just fixed in next, return the original promise, and do the capturing of errors separately?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see: #7456

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is freaking cursed that this is even a possibility LOL

but yes we should 😞

@AbhiPrasad
AbhiPrasad enabled auto-merge (squash) March 14, 2023 17:34
@AbhiPrasad
AbhiPrasad merged commit b1ef00d into developMar 14, 2023
@AbhiPrasad
AbhiPrasad deleted the abhi-sveltekit-server-load-error branch March 14, 2023 17:41
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add SvelteKit server-side error monitoring instrumentation

2 participants

@AbhiPrasad@mydea