Skip to content

Commit 5b4c45f

Browse files
Lms24cursoragent
andcommitted
feat(sveltekit): Set url.template, url.path and url.full on pageload and navigation spans
Adds the url.template attribute to SvelteKit pageload and navigation root spans (using the shared @sentry/conventions attribute keys), and passes the absolute navigation URL through to startBrowserTracingNavigationSpan so that url.full and url.path are set as well. part of #21921 Co-Authored-By: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 9fa0ae8 commit 5b4c45f

9 files changed

Lines changed: 198 additions & 31 deletions

File tree

dev-packages/e2e-tests/test-applications/sveltekit-2-kit-tracing/tests/tracing.client.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ test.describe('client-specific performance events', () => {
3636
op: 'navigation',
3737
origin: 'auto.navigation.sveltekit',
3838
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
39+
data: {
40+
'url.path': '/nav1',
41+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/nav1$/),
42+
'url.template': '/nav1',
43+
},
3944
},
4045
},
4146
});
@@ -49,6 +54,11 @@ test.describe('client-specific performance events', () => {
4954
op: 'navigation',
5055
origin: 'auto.navigation.sveltekit',
5156
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
57+
data: {
58+
'url.path': '/',
59+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/$/),
60+
'url.template': '/',
61+
},
5262
},
5363
},
5464
});
@@ -62,6 +72,11 @@ test.describe('client-specific performance events', () => {
6272
op: 'navigation',
6373
origin: 'auto.navigation.sveltekit',
6474
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
75+
data: {
76+
'url.path': '/nav2',
77+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/nav2$/),
78+
'url.template': '/nav2',
79+
},
6580
},
6681
},
6782
});

dev-packages/e2e-tests/test-applications/sveltekit-2-kit-tracing/tests/tracing.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ test('capture a distributed pageload trace', async ({ page }) => {
2626
trace: {
2727
op: 'pageload',
2828
origin: 'auto.pageload.sveltekit',
29+
data: {
30+
'url.path': '/users/123xyz',
31+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users\/123xyz$/),
32+
'url.template': '/users/[id]',
33+
},
2934
},
3035
},
3136
});
@@ -88,6 +93,11 @@ test('capture a distributed navigation trace', async ({ page }) => {
8893
trace: {
8994
op: 'navigation',
9095
origin: 'auto.navigation.sveltekit',
96+
data: {
97+
'url.path': '/users',
98+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users$/),
99+
'url.template': '/users',
100+
},
91101
},
92102
},
93103
});
@@ -139,6 +149,11 @@ test('record client-side universal load fetch span and trace', async ({ page })
139149
trace: {
140150
op: 'navigation',
141151
origin: 'auto.navigation.sveltekit',
152+
data: {
153+
'url.path': '/universal-load-fetch',
154+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/universal-load-fetch$/),
155+
'url.template': '/universal-load-fetch',
156+
},
142157
},
143158
},
144159
});
@@ -212,6 +227,11 @@ test('captures a navigation transaction directly after pageload', async ({ page
212227
trace: {
213228
op: 'pageload',
214229
origin: 'auto.pageload.sveltekit',
230+
data: {
231+
'url.path': '/',
232+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/$/),
233+
'url.template': '/',
234+
},
215235
},
216236
},
217237
});
@@ -228,6 +248,9 @@ test('captures a navigation transaction directly after pageload', async ({ page
228248
'sentry.sveltekit.navigation.from': '/',
229249
'sentry.sveltekit.navigation.to': '/users/[id]',
230250
'sentry.sveltekit.navigation.type': 'link',
251+
'url.path': '/users/123abc',
252+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users\/123abc$/),
253+
'url.template': '/users/[id]',
231254
},
232255
},
233256
},
@@ -290,6 +313,9 @@ test('captures one navigation transaction per redirect', async ({ page }) => {
290313
'sentry.sveltekit.navigation.from': '/',
291314
'sentry.sveltekit.navigation.to': '/redirect1',
292315
'sentry.sample_rate': 1,
316+
'url.path': '/redirect1',
317+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/redirect1$/),
318+
'url.template': '/redirect1',
293319
},
294320
},
295321
},
@@ -327,6 +353,9 @@ test('captures one navigation transaction per redirect', async ({ page }) => {
327353
'sentry.sveltekit.navigation.from': '/',
328354
'sentry.sveltekit.navigation.to': '/redirect2',
329355
'sentry.sample_rate': 1,
356+
'url.path': '/redirect2',
357+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/redirect2$/),
358+
'url.template': '/redirect2',
330359
},
331360
},
332361
},
@@ -364,6 +393,9 @@ test('captures one navigation transaction per redirect', async ({ page }) => {
364393
'sentry.sveltekit.navigation.from': '/',
365394
'sentry.sveltekit.navigation.to': '/users/[id]',
366395
'sentry.sample_rate': 1,
396+
'url.path': '/users/789',
397+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users\/789$/),
398+
'url.template': '/users/[id]',
367399
},
368400
},
369401
},

dev-packages/e2e-tests/test-applications/sveltekit-2-svelte-5/tests/performance.client.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ test.describe('client-specific performance events', () => {
3636
op: 'navigation',
3737
origin: 'auto.navigation.sveltekit',
3838
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
39+
data: {
40+
'url.path': '/nav1',
41+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/nav1$/),
42+
'url.template': '/nav1',
43+
},
3944
},
4045
},
4146
});
@@ -49,6 +54,11 @@ test.describe('client-specific performance events', () => {
4954
op: 'navigation',
5055
origin: 'auto.navigation.sveltekit',
5156
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
57+
data: {
58+
'url.path': '/',
59+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/$/),
60+
'url.template': '/',
61+
},
5262
},
5363
},
5464
});
@@ -62,6 +72,11 @@ test.describe('client-specific performance events', () => {
6272
op: 'navigation',
6373
origin: 'auto.navigation.sveltekit',
6474
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
75+
data: {
76+
'url.path': '/nav2',
77+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/nav2$/),
78+
'url.template': '/nav2',
79+
},
6580
},
6681
},
6782
});

dev-packages/e2e-tests/test-applications/sveltekit-2-svelte-5/tests/performance.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ test.describe('performance events', () => {
2727
trace: {
2828
op: 'pageload',
2929
origin: 'auto.pageload.sveltekit',
30+
data: {
31+
'url.path': '/users/123xyz',
32+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users\/123xyz$/),
33+
'url.template': '/users/[id]',
34+
},
3035
},
3136
},
3237
});
@@ -81,6 +86,11 @@ test.describe('performance events', () => {
8186
trace: {
8287
op: 'navigation',
8388
origin: 'auto.navigation.sveltekit',
89+
data: {
90+
'url.path': '/users',
91+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users$/),
92+
'url.template': '/users',
93+
},
8494
},
8595
},
8696
});
@@ -132,6 +142,11 @@ test.describe('performance events', () => {
132142
trace: {
133143
op: 'navigation',
134144
origin: 'auto.navigation.sveltekit',
145+
data: {
146+
'url.path': '/universal-load-fetch',
147+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/universal-load-fetch$/),
148+
'url.template': '/universal-load-fetch',
149+
},
135150
},
136151
},
137152
});
@@ -205,6 +220,11 @@ test.describe('performance events', () => {
205220
trace: {
206221
op: 'pageload',
207222
origin: 'auto.pageload.sveltekit',
223+
data: {
224+
'url.path': '/',
225+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/$/),
226+
'url.template': '/',
227+
},
208228
},
209229
},
210230
});
@@ -221,6 +241,9 @@ test.describe('performance events', () => {
221241
'sentry.sveltekit.navigation.from': '/',
222242
'sentry.sveltekit.navigation.to': '/users/[id]',
223243
'sentry.sveltekit.navigation.type': 'link',
244+
'url.path': '/users/123abc',
245+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users\/123abc$/),
246+
'url.template': '/users/[id]',
224247
},
225248
},
226249
},
@@ -283,6 +306,9 @@ test.describe('performance events', () => {
283306
'sentry.sveltekit.navigation.from': '/',
284307
'sentry.sveltekit.navigation.to': '/redirect1',
285308
'sentry.sample_rate': 1,
309+
'url.path': '/redirect1',
310+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/redirect1$/),
311+
'url.template': '/redirect1',
286312
},
287313
},
288314
},
@@ -320,6 +346,9 @@ test.describe('performance events', () => {
320346
'sentry.sveltekit.navigation.from': '/',
321347
'sentry.sveltekit.navigation.to': '/redirect2',
322348
'sentry.sample_rate': 1,
349+
'url.path': '/redirect2',
350+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/redirect2$/),
351+
'url.template': '/redirect2',
323352
},
324353
},
325354
},
@@ -357,6 +386,9 @@ test.describe('performance events', () => {
357386
'sentry.sveltekit.navigation.from': '/',
358387
'sentry.sveltekit.navigation.to': '/users/[id]',
359388
'sentry.sample_rate': 1,
389+
'url.path': '/users/789',
390+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users\/789$/),
391+
'url.template': '/users/[id]',
360392
},
361393
},
362394
},

dev-packages/e2e-tests/test-applications/sveltekit-2/tests/performance.client.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ test.describe('client-specific performance events', () => {
3131
op: 'navigation',
3232
origin: 'auto.navigation.sveltekit',
3333
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
34+
data: {
35+
'url.path': '/nav1',
36+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/nav1$/),
37+
'url.template': '/nav1',
38+
},
3439
},
3540
},
3641
});
@@ -44,6 +49,11 @@ test.describe('client-specific performance events', () => {
4449
op: 'navigation',
4550
origin: 'auto.navigation.sveltekit',
4651
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
52+
data: {
53+
'url.path': '/',
54+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/$/),
55+
'url.template': '/',
56+
},
4757
},
4858
},
4959
});
@@ -57,6 +67,11 @@ test.describe('client-specific performance events', () => {
5767
op: 'navigation',
5868
origin: 'auto.navigation.sveltekit',
5969
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
70+
data: {
71+
'url.path': '/nav2',
72+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/nav2$/),
73+
'url.template': '/nav2',
74+
},
6075
},
6176
},
6277
});

dev-packages/e2e-tests/test-applications/sveltekit-2/tests/performance.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ test.describe('performance events', () => {
2727
trace: {
2828
op: 'pageload',
2929
origin: 'auto.pageload.sveltekit',
30+
data: {
31+
'url.path': '/users/123xyz',
32+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users\/123xyz$/),
33+
'url.template': '/users/[id]',
34+
},
3035
},
3136
},
3237
});
@@ -81,6 +86,11 @@ test.describe('performance events', () => {
8186
trace: {
8287
op: 'navigation',
8388
origin: 'auto.navigation.sveltekit',
89+
data: {
90+
'url.path': '/users',
91+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users$/),
92+
'url.template': '/users',
93+
},
8494
},
8595
},
8696
});
@@ -132,6 +142,11 @@ test.describe('performance events', () => {
132142
trace: {
133143
op: 'navigation',
134144
origin: 'auto.navigation.sveltekit',
145+
data: {
146+
'url.path': '/universal-load-fetch',
147+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/universal-load-fetch$/),
148+
'url.template': '/universal-load-fetch',
149+
},
135150
},
136151
},
137152
});
@@ -205,6 +220,11 @@ test.describe('performance events', () => {
205220
trace: {
206221
op: 'pageload',
207222
origin: 'auto.pageload.sveltekit',
223+
data: {
224+
'url.path': '/',
225+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/$/),
226+
'url.template': '/',
227+
},
208228
},
209229
},
210230
});
@@ -221,6 +241,9 @@ test.describe('performance events', () => {
221241
'sentry.sveltekit.navigation.from': '/',
222242
'sentry.sveltekit.navigation.to': '/users/[id]',
223243
'sentry.sveltekit.navigation.type': 'link',
244+
'url.path': '/users/123abc',
245+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users\/123abc$/),
246+
'url.template': '/users/[id]',
224247
},
225248
},
226249
},
@@ -283,6 +306,9 @@ test.describe('performance events', () => {
283306
'sentry.sveltekit.navigation.from': '/',
284307
'sentry.sveltekit.navigation.to': '/redirect1',
285308
'sentry.sample_rate': 1,
309+
'url.path': '/redirect1',
310+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/redirect1$/),
311+
'url.template': '/redirect1',
286312
},
287313
},
288314
},
@@ -320,6 +346,9 @@ test.describe('performance events', () => {
320346
'sentry.sveltekit.navigation.from': '/',
321347
'sentry.sveltekit.navigation.to': '/redirect2',
322348
'sentry.sample_rate': 1,
349+
'url.path': '/redirect2',
350+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/redirect2$/),
351+
'url.template': '/redirect2',
323352
},
324353
},
325354
},
@@ -357,6 +386,9 @@ test.describe('performance events', () => {
357386
'sentry.sveltekit.navigation.from': '/',
358387
'sentry.sveltekit.navigation.to': '/users/[id]',
359388
'sentry.sample_rate': 1,
389+
'url.path': '/users/789',
390+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/users\/789$/),
391+
'url.template': '/users/[id]',
360392
},
361393
},
362394
},

packages/sveltekit/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"dependencies": {
5454
"@sentry/cloudflare": "10.64.0",
5555
"@sentry/core": "10.64.0",
56+
"@sentry/conventions": "^0.15.1",
5657
"@sentry/node": "10.64.0",
5758
"@sentry/svelte": "10.64.0",
5859
"@sentry/vite-plugin": "^5.3.0",

0 commit comments

Comments
 (0)