File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
packages/sveltekit/src/server Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,24 @@ export function sentryHandle(handlerOptions?: SentryHandleOptions): Handle {
149
149
} ;
150
150
151
151
const sentryRequestHandler : Handle = input => {
152
+ // event.isSubRequest was added in SvelteKit 1.21.0 and we can use it to check
153
+ // if we should create a new execution context or not.
154
+ // In case of a same-origin `fetch` call within a server`load` function,
155
+ // SvelteKit will actually just re-enter the `handle` function and set `isSubRequest`
156
+ // to `true` so that no additional network call is made.
157
+ // We want the `http.server` span of that nested call to be a child span of the
158
+ // currently active span instead of a new root span to correctly reflect this
159
+ // behavior.
160
+ // Type-casting to boolean | undefined to reflect that kit <1.21.0 doesn't have this property
161
+ const isSubRequest = input . event . isSubRequest as boolean | undefined ;
162
+ if ( isSubRequest ) {
163
+ return instrumentHandle ( input , options ) ;
164
+ }
165
+ if ( isSubRequest === false ) {
166
+ return withIsolationScope ( ( ) => instrumentHandle ( input , options ) ) ;
167
+ }
168
+
169
+ // Fallback for Sveltekit < 1.21.0
152
170
// if there is an active span, we know that this handle call is nested and hence
153
171
// we don't create a new execution context for it.
154
172
// If we created one, nested server calls would create new root span instead
You can’t perform that action at this time.
0 commit comments