Skip to content

Commit 0ed4606

Browse files
isaacsclaude
andauthored
fix(sveltekit): add op and origin to Kit's sveltekit.endpoint span (#25376)
SvelteKit 3.1.0 emits a `sveltekit.endpoint` span for `+server` handlers when server tracing is on. The SDK did not know the span, so it went out with origin `manual` and no op, unlike Kit's other spans. It also broke the `sveltekit-3` e2e test, which counts the child spans of a page that fetches a `+server` route. The span now gets op `function` and origin `auto.function.sveltekit.endpoint`. The origin follows the trace origin format and the other Kit span origins (`auto.function.sveltekit.load`, `auto.function.sveltekit.action`). Its part keeps the span apart from the SDK's own `wrapServerRouteWithSentry` span (`auto.function.sveltekit`), which can now appear next to it. Under span streaming, the span also gets `sentry.description`, as Kit's other spans do, because the `function` description template needs `code.function.name`, which Kit does not set. Re: sveltejs/kit#17325 Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 9516aeb commit 0ed4606

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎dev-packages/e2e-tests/test-applications/sveltekit-3/tests/tracing.server.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test('server pageload request span has nested request span for sub request', asy
2626

2727
const spans = getSegmentChildSpans(serverTraceSpans, serverSpan);
2828

29-
expect(spans).toHaveLength(6);
29+
expect(spans).toHaveLength(7);
3030

3131
expect(spans).toEqual(
3232
expect.arrayContaining([
@@ -102,6 +102,19 @@ test('server pageload request span has nested request span for sub request', asy
102102
'http.route': { value: '/api/users', type: 'string' },
103103
}),
104104
}),
105+
106+
// sub request `+server` handler span (emitted by Kit since 3.1.0):
107+
expect.objectContaining({
108+
name: 'sveltekit.endpoint',
109+
status: 'ok',
110+
attributes: expect.objectContaining({
111+
'sentry.op': { value: 'function', type: 'string' },
112+
'sentry.origin': { value: 'auto.function.sveltekit.endpoint', type: 'string' },
113+
'sentry.description': { value: 'sveltekit.endpoint', type: 'string' },
114+
'http.route': { value: '/api/users', type: 'string' },
115+
'http.method': { value: 'GET', type: 'string' },
116+
}),
117+
}),
105118
]),
106119
);
107120
});

‎packages/sveltekit/src/server-common/integrations/svelteKitSpans.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ function _getKitSpanOrigin(spanName: string | undefined): SpanOrigin | undefined
8484
return 'auto.function.sveltekit.load';
8585
case 'sveltekit.form_action':
8686
return 'auto.function.sveltekit.action';
87+
case 'sveltekit.endpoint':
88+
return 'auto.function.sveltekit.endpoint';
8789
case 'sveltekit.remote.call':
8890
return 'auto.rpc.sveltekit.remote';
8991
case 'sveltekit.handle.root':

‎packages/sveltekit/test/server-common/integrations/svelteKitSpans.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe('svelteKitSpansIntegration', () => {
5656
['sveltekit.resolve', 'function', 'auto.http.sveltekit'],
5757
['sveltekit.load', 'function', 'auto.function.sveltekit.load'],
5858
['sveltekit.form_action', 'function', 'auto.function.sveltekit.action'],
59+
['sveltekit.endpoint', 'function', 'auto.function.sveltekit.endpoint'],
5960
['sveltekit.remote.call', 'function', 'auto.rpc.sveltekit.remote'],
6061
['sveltekit.handle.sequenced.0', 'function', 'auto.function.sveltekit.handle'],
6162
['sveltekit.handle.sequenced.myHandler', 'function', 'auto.function.sveltekit.handle'],
@@ -194,6 +195,7 @@ describe('svelteKitSpansIntegration', () => {
194195
['sveltekit.resolve', 'function', 'auto.http.sveltekit'],
195196
['sveltekit.load', 'function', 'auto.function.sveltekit.load'],
196197
['sveltekit.form_action', 'function', 'auto.function.sveltekit.action'],
198+
['sveltekit.endpoint', 'function', 'auto.function.sveltekit.endpoint'],
197199
['sveltekit.remote.call', 'function', 'auto.rpc.sveltekit.remote'],
198200
['sveltekit.handle.sequenced.0', 'function', 'auto.function.sveltekit.handle'],
199201
['sveltekit.handle.sequenced.myHandler', 'function', 'auto.function.sveltekit.handle'],

0 commit comments

Comments
 (0)