Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ test('Sends a pageload transaction to Sentry', async ({ page }) => {
expect(transactionEvent.contexts?.trace?.data).toEqual(
expect.objectContaining({
'sentry.origin': 'auto.pageload.remix',
'sentry.source': 'url',
'sentry.source': 'route',
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/$/),
'url.path': '/',
'url.template': '/',
}),
);
// no url.template because the route isn't parameterized (sentry.source: 'url')
expect(transactionEvent.contexts?.trace?.data).not.toHaveProperty('url.template');
});

test('Sends a navigation transaction to Sentry', async ({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ test('Sends a pageload transaction to Sentry', async ({ page }) => {
expect(transactionEvent.contexts?.trace?.data).toEqual(
expect.objectContaining({
'sentry.origin': 'auto.pageload.remix',
'sentry.source': 'url',
'sentry.source': 'route',
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/$/),
'url.path': '/',
'url.template': '/',
}),
);
// no url.template because the route isn't parameterized (sentry.source: 'url')
expect(transactionEvent.contexts?.trace?.data).not.toHaveProperty('url.template');
});

test('Sends a navigation transaction to Sentry', async ({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ test('Sends a pageload transaction to Sentry', async ({ page }) => {
expect(transactionEvent).toBeDefined();
expect(transactionEvent.contexts?.trace?.data).toEqual(
expect.objectContaining({
'sentry.source': 'url',
'sentry.source': 'route',
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/$/),
'url.path': '/',
'url.template': '/',
}),
);
// no url.template because the route isn't parameterized (sentry.source: 'url')
expect(transactionEvent.contexts?.trace?.data).not.toHaveProperty('url.template');
});

test('Sends a navigation transaction to Sentry', async ({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ test('Sends a pageload transaction to Sentry', async ({ page }) => {
contexts: {
trace: {
data: {
'sentry.source': 'url',
'sentry.source': 'route',
'url.full': expect.stringMatching(/^https?:\/\/localhost:\d+\/$/),
'url.path': '/',
'url.template': '/',
},
},
},
});
// no url.template because the route isn't parameterized (sentry.source: 'url')
expect(transactionEvent.contexts?.trace?.data).not.toHaveProperty('url.template');
});

test('Sends a navigation transaction to Sentry', async ({ page }) => {
Expand Down
8 changes: 3 additions & 5 deletions packages/remix/src/client/performance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function getInitPathName(): string | undefined {
/**
* Determines the transaction name and source for a route.
* Handles three cases:
* 1. Dynamic routes with manifest (Vite apps): Use parameterized path with source 'route'
* 2. Static routes with manifest (Vite apps): Use pathname with source 'url'
* 1. Routes resolved from the manifest (Vite apps): Use the route template with source 'route'
* 2. Routes the manifest doesn't know, e.g. 404s (Vite apps): Use pathname with source 'url'
* 3. Legacy apps without manifest: Use route ID with source 'route'
*/
function getTransactionNameAndSource(
Expand All @@ -73,13 +73,11 @@ function getTransactionNameAndSource(
const parameterizedRoute = pathname ? maybeParameterizeRemixRoute(pathname) : undefined;

if (parameterizedRoute) {
// We have a parameterized route from the manifest (dynamic route)
return { name: parameterizedRoute, source: 'route' };
}

if (hasManifest()) {
// We have a manifest but no parameterization (static route)
// Use the pathname with source 'url'
// The manifest doesn't know this route, so the pathname may well be high cardinality.
return { name: pathname || routeId, source: 'url' };
}

Expand Down
6 changes: 3 additions & 3 deletions packages/remix/src/client/remixRouteParameterization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ function findMatchingRoutes(
): string[] {
const matches: string[] = [];

// Static routes don't need parameterization - return empty to keep source as 'url'
// Static routes don't need parameterization, return the route itself as already parameterized
if (staticRoutes.some(r => r.path === route)) {
return matches;
return [route];
}

// Check dynamic routes
Expand Down Expand Up @@ -142,7 +142,7 @@ export function hasManifest(): boolean {
* Parameterize a route using the route manifest.
*
* @param route - The route to parameterize.
* @returns The parameterized route or undefined if no parameterization is needed.
* @returns The parameterized route or undefined if not able to parameterize.
*/
export const maybeParameterizeRemixRoute = (route: string): string | undefined => {
const manifest = getManifest();
Expand Down
24 changes: 12 additions & 12 deletions packages/remix/test/client/remixRouteParameterization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ describe('maybeParameterizeRemixRoute', () => {
});

describe('when manifest has static routes', () => {
it('should return undefined for static routes', () => {
it('returns the route itself for static routes', () => {
const manifest: RouteManifest = {
staticRoutes: [{ path: '/' }, { path: '/about' }, { path: '/contact' }, { path: '/blog/posts' }],
dynamicRoutes: [],
};
globalWithInjectedManifest._sentryRemixRouteManifest = JSON.stringify(manifest);

expect(maybeParameterizeRemixRoute('/')).toBeUndefined();
expect(maybeParameterizeRemixRoute('/about')).toBeUndefined();
expect(maybeParameterizeRemixRoute('/contact')).toBeUndefined();
expect(maybeParameterizeRemixRoute('/blog/posts')).toBeUndefined();
expect(maybeParameterizeRemixRoute('/')).toBe('/');
expect(maybeParameterizeRemixRoute('/about')).toBe('/about');
expect(maybeParameterizeRemixRoute('/contact')).toBe('/contact');
expect(maybeParameterizeRemixRoute('/blog/posts')).toBe('/blog/posts');
});
});

Expand Down Expand Up @@ -84,8 +84,8 @@ describe('maybeParameterizeRemixRoute', () => {
};
globalWithInjectedManifest._sentryRemixRouteManifest = JSON.stringify(manifest);

expect(maybeParameterizeRemixRoute('/')).toBeUndefined();
expect(maybeParameterizeRemixRoute('/about')).toBeUndefined();
expect(maybeParameterizeRemixRoute('/')).toBe('/');
expect(maybeParameterizeRemixRoute('/about')).toBe('/about');
});

it('should handle splat/catch-all routes', () => {
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('maybeParameterizeRemixRoute', () => {
};
globalWithInjectedManifest._sentryRemixRouteManifest = JSON.stringify(manifest);

expect(maybeParameterizeRemixRoute('/')).toBeUndefined();
expect(maybeParameterizeRemixRoute('/')).toBe('/');
});

it('should handle complex nested dynamic routes', () => {
Expand All @@ -246,10 +246,10 @@ describe('maybeParameterizeRemixRoute', () => {

describe('realistic Remix patterns', () => {
it.each([
['/', undefined],
['/about', undefined],
['/contact', undefined],
['/blog/posts', undefined],
['/', '/'],
['/about', '/about'],
['/contact', '/contact'],
['/blog/posts', '/blog/posts'],

['/users/123', '/users/:id'],
['/users/john-doe', '/users/:id'],
Expand Down
Loading