From 98f6e9efc49e6543678202d4b4fcb5b67a300fe2 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 7 Jul 2026 11:29:41 +0200 Subject: [PATCH] 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 --- .../astro-4/tests/tracing.dynamic.test.ts | 3 +++ .../astro-4/tests/tracing.static.test.ts | 3 +++ .../astro-5/tests/tracing.dynamic.test.ts | 12 ++++++++++++ .../astro-5/tests/tracing.serverIslands.test.ts | 3 +++ .../astro-5/tests/tracing.static.test.ts | 3 +++ .../astro-6/tests/tracing.dynamic.test.ts | 12 ++++++++++++ .../astro-6/tests/tracing.serverIslands.test.ts | 3 +++ .../astro-6/tests/tracing.static.test.ts | 3 +++ packages/astro/package.json | 1 + .../astro/src/client/browserTracingIntegration.ts | 2 ++ 10 files changed, 45 insertions(+) diff --git a/dev-packages/e2e-tests/test-applications/astro-4/tests/tracing.dynamic.test.ts b/dev-packages/e2e-tests/test-applications/astro-4/tests/tracing.dynamic.test.ts index 4d3d93fdf81e..e9d7c87eb5ac 100644 --- a/dev-packages/e2e-tests/test-applications/astro-4/tests/tracing.dynamic.test.ts +++ b/dev-packages/e2e-tests/test-applications/astro-4/tests/tracing.dynamic.test.ts @@ -32,6 +32,9 @@ test.describe('tracing in dynamically rendered (ssr) routes', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/test-ssr', + 'url.path': '/test-ssr', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/test-ssr$/), }), op: 'pageload', origin: 'auto.pageload.astro', diff --git a/dev-packages/e2e-tests/test-applications/astro-4/tests/tracing.static.test.ts b/dev-packages/e2e-tests/test-applications/astro-4/tests/tracing.static.test.ts index 7af2115dc29e..f1cfcc78789c 100644 --- a/dev-packages/e2e-tests/test-applications/astro-4/tests/tracing.static.test.ts +++ b/dev-packages/e2e-tests/test-applications/astro-4/tests/tracing.static.test.ts @@ -37,6 +37,9 @@ test.describe('tracing in static/pre-rendered routes', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/test-static', + 'url.path': '/test-static', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/test-static$/), }), op: 'pageload', origin: 'auto.pageload.astro', diff --git a/dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.dynamic.test.ts b/dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.dynamic.test.ts index 0c69d1f59698..9a6ab99afbec 100644 --- a/dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.dynamic.test.ts +++ b/dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.dynamic.test.ts @@ -32,6 +32,9 @@ test.describe('tracing in dynamically rendered (ssr) routes', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/test-ssr', + 'url.path': '/test-ssr', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/test-ssr$/), }), op: 'pageload', origin: 'auto.pageload.astro', @@ -213,6 +216,9 @@ test.describe('nested SSR routes (client, server, server request)', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/user-page/[userId]', + 'url.path': '/user-page/myUsername123', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/user-page\/myUsername123$/), }, }, }, @@ -309,6 +315,9 @@ test.describe('nested SSR routes (client, server, server request)', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/catchAll/[...path]', + 'url.path': '/catchAll/hell0/whatever-do', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/catchAll\/hell0\/whatever-do$/), }, }, }, @@ -366,6 +375,9 @@ test.describe('parametrized vs static paths', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/user-page/settings', + 'url.path': '/user-page/settings', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/user-page\/settings$/), }, }, }, diff --git a/dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.serverIslands.test.ts b/dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.serverIslands.test.ts index 354655a4ac7e..1416a706f971 100644 --- a/dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.serverIslands.test.ts +++ b/dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.serverIslands.test.ts @@ -33,6 +33,9 @@ test.describe('tracing in static routes with server islands', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/server-island', + 'url.path': '/server-island', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/server-island$/), }), op: 'pageload', origin: 'auto.pageload.astro', diff --git a/dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.static.test.ts b/dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.static.test.ts index 4563dc2f306d..8297dd2b08a5 100644 --- a/dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.static.test.ts +++ b/dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.static.test.ts @@ -37,6 +37,9 @@ test.describe('tracing in static/pre-rendered routes', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/test-static', + 'url.path': '/test-static', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/test-static$/), }), op: 'pageload', origin: 'auto.pageload.astro', diff --git a/dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.dynamic.test.ts b/dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.dynamic.test.ts index a89d1efd9f3a..83f6db0fae4f 100644 --- a/dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.dynamic.test.ts +++ b/dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.dynamic.test.ts @@ -32,6 +32,9 @@ test.describe('tracing in dynamically rendered (ssr) routes', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/test-ssr', + 'url.path': '/test-ssr', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/test-ssr$/), }), op: 'pageload', origin: 'auto.pageload.astro', @@ -213,6 +216,9 @@ test.describe('nested SSR routes (client, server, server request)', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/user-page/[userId]', + 'url.path': '/user-page/myUsername123', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/user-page\/myUsername123$/), }, }, }, @@ -309,6 +315,9 @@ test.describe('nested SSR routes (client, server, server request)', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/catchAll/[...path]', + 'url.path': '/catchAll/hell0/whatever-do', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/catchAll\/hell0\/whatever-do$/), }, }, }, @@ -366,6 +375,9 @@ test.describe('parametrized vs static paths', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/user-page/settings', + 'url.path': '/user-page/settings', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/user-page\/settings$/), }, }, }, diff --git a/dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.serverIslands.test.ts b/dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.serverIslands.test.ts index 829b44a035f3..ce30defcd1fa 100644 --- a/dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.serverIslands.test.ts +++ b/dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.serverIslands.test.ts @@ -33,6 +33,9 @@ test.describe('tracing in static routes with server islands', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/server-island', + 'url.path': '/server-island', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/server-island$/), }), op: 'pageload', origin: 'auto.pageload.astro', diff --git a/dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.static.test.ts b/dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.static.test.ts index c76a66101775..23a54221de50 100644 --- a/dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.static.test.ts +++ b/dev-packages/e2e-tests/test-applications/astro-6/tests/tracing.static.test.ts @@ -37,6 +37,9 @@ test.describe('tracing in static/pre-rendered routes', () => { 'sentry.op': 'pageload', 'sentry.origin': 'auto.pageload.astro', 'sentry.source': 'route', + 'url.template': '/test-static', + 'url.path': '/test-static', + 'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/test-static$/), }), op: 'pageload', origin: 'auto.pageload.astro', diff --git a/packages/astro/package.json b/packages/astro/package.json index 88929b830561..387a5a54da6f 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -58,6 +58,7 @@ "dependencies": { "@sentry/browser": "10.64.0", "@sentry/core": "10.64.0", + "@sentry/conventions": "^0.15.1", "@sentry/node": "10.64.0", "@sentry/vite-plugin": "^5.3.0" }, diff --git a/packages/astro/src/client/browserTracingIntegration.ts b/packages/astro/src/client/browserTracingIntegration.ts index 5ffdb3fd8860..219c76902e41 100644 --- a/packages/astro/src/client/browserTracingIntegration.ts +++ b/packages/astro/src/client/browserTracingIntegration.ts @@ -11,6 +11,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, } from '@sentry/core'; import { DEBUG_BUILD } from '../debug-build'; +import { URL_TEMPLATE } from '@sentry/conventions/attributes'; /** * Returns the value of a meta-tag @@ -48,6 +49,7 @@ export function browserTracingIntegration( attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source, [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.astro', + ...(source === 'route' && { [URL_TEMPLATE]: name }), }, }); }