Skip to content

Commit 74164df

Browse files
committed
encode URI
1 parent 04ddbdd commit 74164df

File tree

6 files changed

+60
-11
lines changed

6 files changed

+60
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ test.describe('nested SSR routes (client, server, server request)', () => {
191191
);
192192

193193
const routeNameMetaContent = await page.locator('meta[name="sentry-route-name"]').getAttribute('content');
194-
expect(routeNameMetaContent).toBe('/user-page/[userId]');
194+
expect(routeNameMetaContent).toBe('%2Fuser-page%2F%5BuserId%5D');
195195

196196
// Client pageload transaction - actual URL with pageload operation
197197
expect(clientPageloadTxn).toMatchObject({
@@ -275,7 +275,7 @@ test.describe('nested SSR routes (client, server, server request)', () => {
275275
await page.goto('/catchAll/hell0/whatever-do');
276276

277277
const routeNameMetaContent = await page.locator('meta[name="sentry-route-name"]').getAttribute('content');
278-
expect(routeNameMetaContent).toBe('/catchAll/[path]');
278+
expect(routeNameMetaContent).toBe('%2FcatchAll%2F%5Bpath%5D');
279279

280280
const clientPageloadTxn = await clientPageloadTxnPromise;
281281
const serverPageRequestTxn = await serverPageRequestTxnPromise;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ test.describe('nested SSR routes (client, server, server request)', () => {
194194
);
195195

196196
const routeNameMetaContent = await page.locator('meta[name="sentry-route-name"]').getAttribute('content');
197-
expect(routeNameMetaContent).toBe('/user-page/[userId]');
197+
expect(routeNameMetaContent).toBe('%2Fuser-page%2F%5BuserId%5D');
198198

199199
// Client pageload transaction - actual URL with pageload operation
200200
expect(clientPageloadTxn).toMatchObject({
@@ -278,7 +278,7 @@ test.describe('nested SSR routes (client, server, server request)', () => {
278278
await page.goto('/catchAll/hell0/whatever-do');
279279

280280
const routeNameMetaContent = await page.locator('meta[name="sentry-route-name"]').getAttribute('content');
281-
expect(routeNameMetaContent).toBe('/catchAll/[...path]');
281+
expect(routeNameMetaContent).toBe('%2FcatchAll%2F%5B...path%5D');
282282

283283
const clientPageloadTxn = await clientPageloadTxnPromise;
284284
const serverPageRequestTxn = await serverPageRequestTxnPromise;

dev-packages/e2e-tests/test-applications/nuxt-3-min/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
"start": "node .output/server/index.mjs",
1212
"start:import": "node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs",
1313
"clean": "npx nuxi cleanup",
14-
"test": "playwright test",
14+
"test": "playwright test -g 'distributed tracing'",
1515
"test:build": "pnpm install && pnpm build",
1616
"test:assert": "pnpm test"
1717
},
1818
"dependencies": {
1919
"@sentry/nuxt": "latest || *",
20-
"nuxt": "3.7.0",
21-
"vue": "3.3.4",
22-
"vue-router": "4.2.4"
20+
"nuxt": "3.9.0",
21+
"vue": "latest",
22+
"vue-router": "latest"
2323
},
2424
"devDependencies": {
2525
"@playwright/test": "~1.53.2",

packages/astro/src/client/browserTracingIntegration.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ export function browserTracingIntegration(
3030
const routeNameFromMetaTags = getMetaContent('sentry-route-name');
3131

3232
if (routeNameFromMetaTags) {
33-
DEBUG_BUILD && debug.log(`[Tracing] Using route name from Sentry HTML meta-tag: ${routeNameFromMetaTags}`);
33+
const decodedRouteName = decodeURIComponent(routeNameFromMetaTags);
3434

35-
pageLoadSpan.updateName(routeNameFromMetaTags);
35+
DEBUG_BUILD && debug.log(`[Tracing] Using route name from Sentry HTML meta-tag: ${decodedRouteName}`);
36+
37+
pageLoadSpan.updateName(decodedRouteName);
3638
pageLoadSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route' as TransactionSource);
3739
}
3840
});

packages/astro/src/server/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function addMetaTagToHead(htmlChunk: string, parametrizedRoute?: string): string
258258
return htmlChunk;
259259
}
260260
const metaTags = parametrizedRoute
261-
? `${getTraceMetaTags()}\n<meta name="sentry-route-name" content="${parametrizedRoute}"/>\n`
261+
? `${getTraceMetaTags()}\n<meta name="sentry-route-name" content="${encodeURIComponent(parametrizedRoute)}"/>\n`
262262
: getTraceMetaTags();
263263

264264
if (!metaTags) {

packages/browser/src/tracing/browserTracingIntegration.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = {
309309
* We explicitly export the proper type here, as this has to be extended in some cases.
310310
*/
311311
export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptions> = {}) => {
312+
console.log('init browserTracingIntegration _options', _options);
312313
const latestRoute: RouteInfo = {
313314
name: undefined,
314315
source: undefined,
@@ -349,6 +350,8 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
349350
..._options,
350351
};
351352

353+
console.log('deconstructed beforeStartSpan', beforeStartSpan);
354+
352355
let _collectWebVitals: undefined | (() => void);
353356
let lastInteractionTimestamp: number | undefined;
354357

@@ -360,6 +363,10 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
360363
? beforeStartSpan(startSpanOptions)
361364
: startSpanOptions;
362365

366+
// fixme: this is always undefined
367+
console.log('beforeStartSpan (inside _createRouteSpan)', beforeStartSpan);
368+
console.log('finalStartSpanOptions', finalStartSpanOptions);
369+
363370
const attributes = finalStartSpanOptions.attributes || {};
364371

365372
// If `finalStartSpanOptions.name` is different than `startSpanOptions.name`
@@ -556,6 +563,11 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
556563
}
557564

558565
if (WINDOW.location) {
566+
console.log('window.location', WINDOW.location);
567+
568+
// todo: set globalThis and check if we can access it here
569+
// @ts-ignore
570+
console.log('routemanifest', globalThis._sentryRouteManifest);
559571
if (instrumentPageLoad) {
560572
const origin = browserPerformanceTimeOrigin();
561573
startBrowserTracingPageLoadSpan(client, {
@@ -789,3 +801,38 @@ function isRedirect(activeSpan: Span, lastInteractionTimestamp: number | undefin
789801

790802
return true;
791803
}
804+
805+
/**
806+
* return originalBrowserTracingIntegration({
807+
* ...options,
808+
* beforeStartSpan: (startSpanOptions) => {
809+
* console.log('beforeStartSpan called with options:', startSpanOptions);
810+
*
811+
* const routeName = getMetaContent('sentry-route-name');
812+
* console.log('astro routeName from beforeStartSpan:', routeName);
813+
*
814+
* if (routeName) {
815+
* const modifiedOptions = {
816+
* ...startSpanOptions,
817+
* name: routeName,
818+
* attributes: {
819+
* ...startSpanOptions.attributes,
820+
* [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route' as TransactionSource,
821+
* },
822+
* };
823+
* console.log('modified options:', modifiedOptions);
824+
* return modifiedOptions;
825+
* }
826+
*
827+
*
828+
* if (options.beforeStartSpan) {
829+
* return options.beforeStartSpan(startSpanOptions);
830+
* }
831+
*
832+
* return startSpanOptions;
833+
* },
834+
* });
835+
* }
836+
*
837+
* export { browserTracingIntegration };
838+
*/

0 commit comments

Comments
 (0)