MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / wrapLoadWithSentry

Function wrapLoadWithSentry

packages/sveltekit/src/client/load.ts:58–90  ·  view source on GitHub ↗
(origLoad: T)

Source from the content-addressed store, hash-verified

56// at build time for every route.
57// eslint-disable-next-line @typescript-eslint/no-explicit-any
58export function wrapLoadWithSentry<T extends (...args: any) => any>(origLoad: T): T {
59 return new Proxy(origLoad, {
60 apply: (wrappingTarget, thisArg, args: Parameters<T>) => {
61 // Type casting here because `T` cannot extend `Load` (see comment above function signature)
62 const event = args[0] as PatchedLoadEvent;
63
64 // Check if already wrapped
65 if (event.__sentry_wrapped__) {
66 return wrappingTarget.apply(thisArg, args);
67 }
68
69 const patchedEvent: PatchedLoadEvent = {
70 ...event,
71 };
72
73 addNonEnumerableProperty(patchedEvent as unknown as Record<string, unknown>, '__sentry_wrapped__', true);
74
75 const routeId = getRouteId(event);
76
77 return startSpan(
78 {
79 op: 'function.sveltekit.load',
80 attributes: {
81 [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.sveltekit',
82 [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: routeId ? 'route' : 'url',
83 },
84 name: routeId ? routeId : event.url.pathname,
85 },
86 () => handleCallbackErrors(() => wrappingTarget.apply(thisArg, [patchedEvent]), sendErrorToSentry),
87 );
88 },
89 });
90}

Callers 2

load.test.tsFile · 0.90
load.test.tsFile · 0.90

Calls 5

addNonEnumerablePropertyFunction · 0.90
getRouteIdFunction · 0.90
startSpanFunction · 0.90
handleCallbackErrorsFunction · 0.90
applyMethod · 0.45

Tested by

no test coverage detected