Skip to content
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

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

Merged
merged 6 commits into from
Mar 14, 2023

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Mar 10, 2023

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 * as db from '$lib/server/database';
 
/** @type {import('./$types').LayoutServerLoad} */
async function customLoad() {
  return {
    posts: await db.getPostSummaries()
  };
}

export const load = 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 * as db from '$lib/server/database';
 
/** @type {import('./$types').PageServerLoad} */
export async function load({ params }) {
  const post = await db.getPost(params.slug);
 
  if (!post) {
    throw error(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
Copy link
Contributor

github-actions bot commented Mar 10, 2023

size-limit report 📦

Path Size
@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 AbhiPrasad force-pushed the abhi-sveltekit-server-load-error branch from b2db998 to e4aa3f4 Compare March 13, 2023 09:58
@AbhiPrasad AbhiPrasad force-pushed the abhi-sveltekit-server-load-error branch from e4aa3f4 to afddce3 Compare March 13, 2023 16:17
@AbhiPrasad AbhiPrasad requested review from Lms24 and mydea March 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
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
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
Member Author

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 develop Mar 14, 2023
@AbhiPrasad AbhiPrasad deleted the abhi-sveltekit-server-load-error branch March 14, 2023 17:41
Sign up for free to 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