|
1 | | -import type { Span } from '@sentry/core'; |
| 1 | +import { trace } from '@sentry/core'; |
2 | 2 | import { captureException, getCurrentHub } from '@sentry/svelte'; |
3 | 3 | import { addExceptionMechanism, isThenable, objectify } from '@sentry/utils'; |
4 | 4 | import type { Load } from '@sveltejs/kit'; |
@@ -34,60 +34,21 @@ function sendErrorToSentry(e: unknown): unknown { |
34 | 34 | export function wrapLoadWithSentry(origLoad: Load): Load { |
35 | 35 | return new Proxy(origLoad, { |
36 | 36 | apply: (wrappingTarget, thisArg, args: Parameters<Load>) => { |
37 | | - let maybePromiseResult; |
38 | | - |
39 | 37 | const [event] = args; |
40 | 38 |
|
41 | | - const scope = getCurrentHub().getScope(); |
42 | | - |
43 | | - let activeSpan: Span | undefined = undefined; |
44 | | - let parentSpan: Span | undefined = undefined; |
45 | | - |
46 | | - if (scope) { |
47 | | - parentSpan = scope.getSpan(); |
48 | | - if (parentSpan) { |
49 | | - activeSpan = parentSpan.startChild({ |
50 | | - op: 'function.sveltekit.load', |
51 | | - description: event.route.id || '/', |
52 | | - }); |
53 | | - |
54 | | - scope.setSpan(activeSpan); |
55 | | - } |
56 | | - } |
57 | | - |
58 | | - try { |
59 | | - maybePromiseResult = wrappingTarget.apply(thisArg, args); |
60 | | - } catch (e) { |
61 | | - if (activeSpan) { |
62 | | - activeSpan.setStatus('internal_error'); |
63 | | - activeSpan.finish(); |
64 | | - } |
65 | | - const sentryError = sendErrorToSentry(e); |
66 | | - throw sentryError; |
67 | | - } |
68 | | - |
69 | | - if (isThenable(maybePromiseResult)) { |
70 | | - Promise.resolve(maybePromiseResult).then( |
71 | | - () => { |
72 | | - if (activeSpan) { |
73 | | - activeSpan.finish(); |
74 | | - } |
75 | | - }, |
76 | | - e => { |
77 | | - if (activeSpan) { |
78 | | - activeSpan.setStatus('internal_error'); |
79 | | - activeSpan.finish(); |
80 | | - } |
81 | | - sendErrorToSentry(e); |
| 39 | + const routeId = event.route.id; |
| 40 | + return trace( |
| 41 | + { |
| 42 | + op: 'function.sveltekit.load', |
| 43 | + name: routeId ? routeId : event.url.pathname, |
| 44 | + status: 'ok', |
| 45 | + metadata: { |
| 46 | + source: routeId ? 'route' : 'url', |
82 | 47 | }, |
83 | | - ); |
84 | | - } else { |
85 | | - if (activeSpan) { |
86 | | - activeSpan.finish(); |
87 | | - } |
88 | | - } |
89 | | - |
90 | | - return maybePromiseResult; |
| 48 | + }, |
| 49 | + () => wrappingTarget.apply(thisArg, args), |
| 50 | + sendErrorToSentry, |
| 51 | + ); |
91 | 52 | }, |
92 | 53 | }); |
93 | 54 | } |
0 commit comments