@@ -88,15 +88,28 @@ export function isFetchProxyRequired(version: string): boolean {
8888 return true ;
8989}
9090
91+ interface BackwardsForwardsCompatibleEvent {
92+ /**
93+ * For now taken from: https://github.com/sveltejs/kit/pull/13899
94+ * Access to spans for tracing. If tracing is not enabled or the function is being run in the browser, these spans will do nothing.
95+ * @since 2.30.0
96+ */
97+ tracing ?: {
98+ /** Whether tracing is enabled. */
99+ enabled : boolean ;
100+ // omitting other properties for now, since we don't use them.
101+ } ;
102+ }
103+
91104async function instrumentHandle (
92105 {
93106 event,
94107 resolve,
95108 } : {
96- event : Parameters < Handle > [ 0 ] [ 'event' ] ;
109+ event : Parameters < Handle > [ 0 ] [ 'event' ] & BackwardsForwardsCompatibleEvent ;
97110 resolve : Parameters < Handle > [ 0 ] [ 'resolve' ] ;
98111 } ,
99- options : SentryHandleOptions & { svelteKitTracingEnabled : boolean } ,
112+ options : SentryHandleOptions ,
100113) : Promise < Response > {
101114 const routeId = event . route ?. id ;
102115
@@ -127,7 +140,7 @@ async function instrumentHandle(
127140 // We only start a span if SvelteKit's native tracing is not enabled. Two reasons:
128141 // - Used Kit version doesn't yet support tracing
129142 // - Users didn't enable tracing
130- const shouldStartSpan = ! options . svelteKitTracingEnabled ;
143+ const shouldStartSpan = ! event . tracing ?. enabled ;
131144
132145 try {
133146 const resolveWithSentry : ( span ?: Span ) => Promise < Response > = async ( span ?: Span ) => {
@@ -172,19 +185,6 @@ async function instrumentHandle(
172185 }
173186}
174187
175- interface BackwardsForwardsCompatibleEvent {
176- /**
177- * For now taken from: https://github.com/sveltejs/kit/pull/13899
178- * Access to spans for tracing. If tracing is not enabled or the function is being run in the browser, these spans will do nothing.
179- * @since 2.30.0
180- */
181- tracing ?: {
182- /** Whether tracing is enabled. */
183- enabled : boolean ;
184- // omitting other properties for now, since we don't use them.
185- } ;
186- }
187-
188188/**
189189 * A SvelteKit handle function that wraps the request for Sentry error and
190190 * performance monitoring.
@@ -215,18 +215,15 @@ export function sentryHandle(handlerOptions?: SentryHandleOptions): Handle {
215215 '_sentrySkipRequestIsolation' in backwardsForwardsCompatibleEvent . locals &&
216216 backwardsForwardsCompatibleEvent . locals . _sentrySkipRequestIsolation ;
217217
218- const svelteKitTracingEnabled = ! ! backwardsForwardsCompatibleEvent . tracing ?. enabled ;
219-
220218 // In case of a same-origin `fetch` call within a server`load` function,
221219 // SvelteKit will actually just re-enter the `handle` function and set `isSubRequest`
222220 // to `true` so that no additional network call is made.
223221 // We want the `http.server` span of that nested call to be a child span of the
224222 // currently active span instead of a new root span to correctly reflect this
225223 // behavior.
226- if ( skipIsolation || input . event . isSubRequest || svelteKitTracingEnabled ) {
224+ if ( skipIsolation || input . event . isSubRequest ) {
227225 return instrumentHandle ( input , {
228226 ...options ,
229- svelteKitTracingEnabled,
230227 } ) ;
231228 }
232229
@@ -243,7 +240,6 @@ export function sentryHandle(handlerOptions?: SentryHandleOptions): Handle {
243240 return continueTrace ( getTracePropagationData ( input . event ) , ( ) =>
244241 instrumentHandle ( input , {
245242 ...options ,
246- svelteKitTracingEnabled,
247243 } ) ,
248244 ) ;
249245 } ) ;
0 commit comments