Skip to content

Commit a216aac

Browse files
Lms24cursoragent
andcommitted
astro: set url.template on pageload spans
Sets url.template on Astro pageload root spans for parameterized routes, and adjusts e2e tests to assert on url.full, url.path and url.template. Co-Authored-By: Cursor <cursoragent@cursor.com>
1 parent a0cf6b6 commit a216aac

10 files changed

Lines changed: 45 additions & 0 deletions

File tree

dev-packages/e2e-tests/test-applications/astro-4/tests/tracing.dynamic.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ test.describe('tracing in dynamically rendered (ssr) routes', () => {
3232
'sentry.op': 'pageload',
3333
'sentry.origin': 'auto.pageload.astro',
3434
'sentry.source': 'route',
35+
'url.template': '/test-ssr',
36+
'url.path': '/test-ssr',
37+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/test-ssr$/),
3538
}),
3639
op: 'pageload',
3740
origin: 'auto.pageload.astro',

dev-packages/e2e-tests/test-applications/astro-4/tests/tracing.static.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ test.describe('tracing in static/pre-rendered routes', () => {
3737
'sentry.op': 'pageload',
3838
'sentry.origin': 'auto.pageload.astro',
3939
'sentry.source': 'route',
40+
'url.template': '/test-static',
41+
'url.path': '/test-static',
42+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/test-static$/),
4043
}),
4144
op: 'pageload',
4245
origin: 'auto.pageload.astro',

dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.dynamic.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ test.describe('tracing in dynamically rendered (ssr) routes', () => {
3232
'sentry.op': 'pageload',
3333
'sentry.origin': 'auto.pageload.astro',
3434
'sentry.source': 'route',
35+
'url.template': '/test-ssr',
36+
'url.path': '/test-ssr',
37+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/test-ssr$/),
3538
}),
3639
op: 'pageload',
3740
origin: 'auto.pageload.astro',
@@ -213,6 +216,9 @@ test.describe('nested SSR routes (client, server, server request)', () => {
213216
'sentry.op': 'pageload',
214217
'sentry.origin': 'auto.pageload.astro',
215218
'sentry.source': 'route',
219+
'url.template': '/user-page/[userId]',
220+
'url.path': '/user-page/myUsername123',
221+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/user-page\/myUsername123$/),
216222
},
217223
},
218224
},
@@ -309,6 +315,9 @@ test.describe('nested SSR routes (client, server, server request)', () => {
309315
'sentry.op': 'pageload',
310316
'sentry.origin': 'auto.pageload.astro',
311317
'sentry.source': 'route',
318+
'url.template': '/catchAll/[...path]',
319+
'url.path': '/catchAll/hell0/whatever-do',
320+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/catchAll\/hell0\/whatever-do$/),
312321
},
313322
},
314323
},
@@ -366,6 +375,9 @@ test.describe('parametrized vs static paths', () => {
366375
'sentry.op': 'pageload',
367376
'sentry.origin': 'auto.pageload.astro',
368377
'sentry.source': 'route',
378+
'url.template': '/user-page/settings',
379+
'url.path': '/user-page/settings',
380+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/user-page\/settings$/),
369381
},
370382
},
371383
},

dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.serverIslands.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ test.describe('tracing in static routes with server islands', () => {
3333
'sentry.op': 'pageload',
3434
'sentry.origin': 'auto.pageload.astro',
3535
'sentry.source': 'route',
36+
'url.template': '/server-island',
37+
'url.path': '/server-island',
38+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/server-island$/),
3639
}),
3740
op: 'pageload',
3841
origin: 'auto.pageload.astro',

dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.static.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ test.describe('tracing in static/pre-rendered routes', () => {
3737
'sentry.op': 'pageload',
3838
'sentry.origin': 'auto.pageload.astro',
3939
'sentry.source': 'route',
40+
'url.template': '/test-static',
41+
'url.path': '/test-static',
42+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/test-static$/),
4043
}),
4144
op: 'pageload',
4245
origin: 'auto.pageload.astro',

dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.dynamic.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ test.describe('tracing in dynamically rendered (ssr) routes', () => {
3232
'sentry.op': 'pageload',
3333
'sentry.origin': 'auto.pageload.astro',
3434
'sentry.source': 'route',
35+
'url.template': '/test-ssr',
36+
'url.path': '/test-ssr',
37+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/test-ssr$/),
3538
}),
3639
op: 'pageload',
3740
origin: 'auto.pageload.astro',
@@ -213,6 +216,9 @@ test.describe('nested SSR routes (client, server, server request)', () => {
213216
'sentry.op': 'pageload',
214217
'sentry.origin': 'auto.pageload.astro',
215218
'sentry.source': 'route',
219+
'url.template': '/user-page/[userId]',
220+
'url.path': '/user-page/myUsername123',
221+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/user-page\/myUsername123$/),
216222
},
217223
},
218224
},
@@ -309,6 +315,9 @@ test.describe('nested SSR routes (client, server, server request)', () => {
309315
'sentry.op': 'pageload',
310316
'sentry.origin': 'auto.pageload.astro',
311317
'sentry.source': 'route',
318+
'url.template': '/catchAll/[...path]',
319+
'url.path': '/catchAll/hell0/whatever-do',
320+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/catchAll\/hell0\/whatever-do$/),
312321
},
313322
},
314323
},
@@ -366,6 +375,9 @@ test.describe('parametrized vs static paths', () => {
366375
'sentry.op': 'pageload',
367376
'sentry.origin': 'auto.pageload.astro',
368377
'sentry.source': 'route',
378+
'url.template': '/user-page/settings',
379+
'url.path': '/user-page/settings',
380+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/user-page\/settings$/),
369381
},
370382
},
371383
},

dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.serverIslands.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ test.describe('tracing in static routes with server islands', () => {
3333
'sentry.op': 'pageload',
3434
'sentry.origin': 'auto.pageload.astro',
3535
'sentry.source': 'route',
36+
'url.template': '/server-island',
37+
'url.path': '/server-island',
38+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/server-island$/),
3639
}),
3740
op: 'pageload',
3841
origin: 'auto.pageload.astro',

dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.static.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ test.describe('tracing in static/pre-rendered routes', () => {
3737
'sentry.op': 'pageload',
3838
'sentry.origin': 'auto.pageload.astro',
3939
'sentry.source': 'route',
40+
'url.template': '/test-static',
41+
'url.path': '/test-static',
42+
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/test-static$/),
4043
}),
4144
op: 'pageload',
4245
origin: 'auto.pageload.astro',

packages/astro/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"dependencies": {
5959
"@sentry/browser": "10.64.0",
6060
"@sentry/core": "10.64.0",
61+
"@sentry/conventions": "^0.15.1",
6162
"@sentry/node": "10.64.0",
6263
"@sentry/vite-plugin": "^5.3.0"
6364
},

packages/astro/src/client/browserTracingIntegration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
1212
} from '@sentry/core';
1313
import { DEBUG_BUILD } from '../debug-build';
14+
import { URL_TEMPLATE } from '@sentry/conventions/attributes';
1415

1516
/**
1617
* Returns the value of a meta-tag
@@ -48,6 +49,7 @@ export function browserTracingIntegration(
4849
attributes: {
4950
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
5051
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.astro',
52+
...(source === 'route' && { [URL_TEMPLATE]: name }),
5153
},
5254
});
5355
}

0 commit comments

Comments
 (0)