(origLoad: T)
| 56 | // at build time for every route. |
| 57 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 58 | export 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 | } |
no test coverage detected