Skip to content

Commit 41c68b9

Browse files
committed
rewrite using trace
1 parent 8c7a152 commit 41c68b9

File tree

1 file changed

+13
-52
lines changed
  • packages/sveltekit/src/client

1 file changed

+13
-52
lines changed

packages/sveltekit/src/client/load.ts

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Span } from '@sentry/core';
1+
import { trace } from '@sentry/core';
22
import { captureException, getCurrentHub } from '@sentry/svelte';
33
import { addExceptionMechanism, isThenable, objectify } from '@sentry/utils';
44
import type { Load } from '@sveltejs/kit';
@@ -34,60 +34,21 @@ function sendErrorToSentry(e: unknown): unknown {
3434
export function wrapLoadWithSentry(origLoad: Load): Load {
3535
return new Proxy(origLoad, {
3636
apply: (wrappingTarget, thisArg, args: Parameters<Load>) => {
37-
let maybePromiseResult;
38-
3937
const [event] = args;
4038

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',
8247
},
83-
);
84-
} else {
85-
if (activeSpan) {
86-
activeSpan.finish();
87-
}
88-
}
89-
90-
return maybePromiseResult;
48+
},
49+
() => wrappingTarget.apply(thisArg, args),
50+
sendErrorToSentry,
51+
);
9152
},
9253
});
9354
}

0 commit comments

Comments
 (0)