diff --git a/packages/sveltekit/src/server/handle.ts b/packages/sveltekit/src/server/handle.ts index 9bb9de9ce394..3a26ee64fd2a 100644 --- a/packages/sveltekit/src/server/handle.ts +++ b/packages/sveltekit/src/server/handle.ts @@ -3,7 +3,6 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, continueTrace, - getActiveSpan, getCurrentScope, getDefaultIsolationScope, getIsolationScope, @@ -100,19 +99,13 @@ export function sentryHandle(handlerOptions?: SentryHandleOptions): Handle { }; const sentryRequestHandler: Handle = input => { - // event.isSubRequest was added in SvelteKit 1.21.0 and we can use it to check - // if we should create a new execution context or not. // In case of a same-origin `fetch` call within a server`load` function, // SvelteKit will actually just re-enter the `handle` function and set `isSubRequest` // to `true` so that no additional network call is made. // We want the `http.server` span of that nested call to be a child span of the // currently active span instead of a new root span to correctly reflect this // behavior. - // As a fallback for Kit < 1.21.0, we check if there is an active span only if there's none, - // we create a new execution context. - const isSubRequest = typeof input.event.isSubRequest === 'boolean' ? input.event.isSubRequest : !!getActiveSpan(); - - if (isSubRequest) { + if (input.event.isSubRequest) { return instrumentHandle(input, options); } diff --git a/packages/sveltekit/test/server/handle.test.ts b/packages/sveltekit/test/server/handle.test.ts index 150f59ae9bc8..cde6a78f1378 100644 --- a/packages/sveltekit/test/server/handle.test.ts +++ b/packages/sveltekit/test/server/handle.test.ts @@ -149,53 +149,6 @@ describe('sentryHandle', () => { expect(spans).toHaveLength(1); }); - it('[kit>=1.21.0] creates a child span for nested server calls (i.e. if there is an active span)', async () => { - let _span: Span | undefined = undefined; - let txnCount = 0; - client.on('spanEnd', span => { - if (span === getRootSpan(span)) { - _span = span; - ++txnCount; - } - }); - - try { - await sentryHandle()({ - event: mockEvent(), - resolve: async _ => { - // simulating a nested load call: - await sentryHandle()({ - event: mockEvent({ route: { id: 'api/users/details/[id]', isSubRequest: true } }), - resolve: resolve(type, isError), - }); - return mockResponse; - }, - }); - } catch (e) { - // - } - - expect(txnCount).toEqual(1); - expect(_span!).toBeDefined(); - - expect(spanToJSON(_span!).description).toEqual('GET /users/[id]'); - expect(spanToJSON(_span!).op).toEqual('http.server'); - expect(spanToJSON(_span!).status).toEqual(isError ? 'internal_error' : 'ok'); - expect(spanToJSON(_span!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('route'); - - expect(spanToJSON(_span!).timestamp).toBeDefined(); - - const spans = getSpanDescendants(_span!).map(spanToJSON); - - expect(spans).toHaveLength(2); - expect(spans).toEqual( - expect.arrayContaining([ - expect.objectContaining({ op: 'http.server', description: 'GET /users/[id]' }), - expect.objectContaining({ op: 'http.server', description: 'GET api/users/details/[id]' }), - ]), - ); - }); - it('creates a child span for nested server calls (i.e. if there is an active span)', async () => { let _span: Span | undefined = undefined; let txnCount = 0; @@ -212,7 +165,7 @@ describe('sentryHandle', () => { resolve: async _ => { // simulating a nested load call: await sentryHandle()({ - event: mockEvent({ route: { id: 'api/users/details/[id]' } }), + event: mockEvent({ route: { id: 'api/users/details/[id]', isSubRequest: true } }), resolve: resolve(type, isError), }); return mockResponse;