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 @@ -15,7 +15,7 @@
"dependencies": {
"@sentry/solid": "latest || *",
"@tailwindcss/vite": "^4.0.6",
"@tanstack/solid-router": "1.141.8",
"@tanstack/solid-router": "^1.141.8",
"@tanstack/solid-router-devtools": "^1.132.25",
"@tanstack/solid-start": "^1.132.25",
"solid-js": "^1.9.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const indexRoute = createRoute({

const postsRoute = createRoute({
getParentRoute: () => rootRoute,
path: 'posts/',
path: 'posts',
});

const postIdRoute = createRoute({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@sentry/react": "latest || *",
"@tanstack/react-router": "1.64.0",
"@tanstack/react-router": "^1.64.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const indexRoute = createRoute({

const postsRoute = createRoute({
getParentRoute: () => rootRoute,
path: 'posts/',
path: 'posts',
});

const postIdRoute = createRoute({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"@sentry/vue": "latest || *",
"@tanstack/vue-router": "1.141.8",
"@tanstack/vue-router": "^1.141.8",
"vue": "^3.4.15"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const indexRoute = createRoute({

const postsRoute = createRoute({
getParentRoute: () => rootRoute,
path: 'posts/',
path: 'posts',
});

const postIdRoute = createRoute({
Expand Down
31 changes: 19 additions & 12 deletions packages/react/src/tanstackrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@ export function tanstackRouterBrowserTracingIntegration(
);

const lastMatch = matchedRoutes[matchedRoutes.length - 1];
// If we only match __root__, we ended up not matching any route at all, so
// we fall back to the pathname.
const routeMatch = lastMatch?.routeId !== '__root__' ? lastMatch : undefined;

startBrowserTracingPageLoadSpan(client, {
name: lastMatch ? lastMatch.routeId : initialWindowLocation.pathname,
name: routeMatch ? routeMatch.routeId : initialWindowLocation.pathname,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react.tanstack_router',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: lastMatch ? 'route' : 'url',
...routeMatchToParamSpanAttributes(lastMatch),
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: routeMatch ? 'route' : 'url',
...routeMatchToParamSpanAttributes(routeMatch),
},
});
}
Expand All @@ -74,40 +77,44 @@ export function tanstackRouterBrowserTracingIntegration(
return;
}

const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(
const matchedRoutesOnBeforeNavigate = castRouterInstance.matchRoutes(
onBeforeNavigateArgs.toLocation.pathname,
onBeforeNavigateArgs.toLocation.search,
{ preload: false, throwOnError: false },
);

const onBeforeNavigateLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1];
const onBeforeNavigateLastMatch = matchedRoutesOnBeforeNavigate[matchedRoutesOnBeforeNavigate.length - 1];
const onBeforeNavigateRouteMatch =
onBeforeNavigateLastMatch?.routeId !== '__root__' ? onBeforeNavigateLastMatch : undefined;

const navigationLocation = WINDOW.location;
const navigationSpan = startBrowserTracingNavigationSpan(client, {
name: onBeforeNavigateLastMatch ? onBeforeNavigateLastMatch.routeId : navigationLocation.pathname,
name: onBeforeNavigateRouteMatch ? onBeforeNavigateRouteMatch.routeId : navigationLocation.pathname,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.tanstack_router',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: onBeforeNavigateLastMatch ? 'route' : 'url',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: onBeforeNavigateRouteMatch ? 'route' : 'url',
},
});

// In case the user is redirected during navigation we want to update the span with the right value.
const unsubscribeOnResolved = castRouterInstance.subscribe('onResolved', onResolvedArgs => {
unsubscribeOnResolved();
if (navigationSpan) {
const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(
const matchedRoutesOnResolved = castRouterInstance.matchRoutes(
onResolvedArgs.toLocation.pathname,
onResolvedArgs.toLocation.search,
{ preload: false, throwOnError: false },
);

const onResolvedLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1];
const onResolvedLastMatch = matchedRoutesOnResolved[matchedRoutesOnResolved.length - 1];
const onResolvedRouteMatch =
onResolvedLastMatch?.routeId !== '__root__' ? onResolvedLastMatch : undefined;

if (onResolvedLastMatch) {
navigationSpan.updateName(onResolvedLastMatch.routeId);
if (onResolvedRouteMatch) {
navigationSpan.updateName(onResolvedRouteMatch.routeId);
navigationSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
navigationSpan.setAttributes(routeMatchToParamSpanAttributes(onResolvedLastMatch));
navigationSpan.setAttributes(routeMatchToParamSpanAttributes(onResolvedRouteMatch));
}
}
});
Expand Down
31 changes: 19 additions & 12 deletions packages/solid/src/tanstackrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ export function tanstackRouterBrowserTracingIntegration<R extends AnyRouter>(
);

const lastMatch = matchedRoutes[matchedRoutes.length - 1];
// If we only match __root__, we ended up not matching any route at all, so
// we fall back to the pathname.
const routeMatch = lastMatch?.routeId !== '__root__' ? lastMatch : undefined;

startBrowserTracingPageLoadSpan(client, {
name: lastMatch ? lastMatch.routeId : initialWindowLocation.pathname,
name: routeMatch ? routeMatch.routeId : initialWindowLocation.pathname,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.solid.tanstack_router',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: lastMatch ? 'route' : 'url',
...routeMatchToParamSpanAttributes(lastMatch),
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: routeMatch ? 'route' : 'url',
...routeMatchToParamSpanAttributes(routeMatch),
},
});
}
Expand All @@ -73,40 +76,44 @@ export function tanstackRouterBrowserTracingIntegration<R extends AnyRouter>(
return;
}

const onResolvedMatchedRoutes = router.matchRoutes(
const matchedRoutesOnBeforeNavigate = router.matchRoutes(
onBeforeNavigateArgs.toLocation.pathname,
onBeforeNavigateArgs.toLocation.search,
{ preload: false, throwOnError: false },
);

const onBeforeNavigateLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1];
const onBeforeNavigateLastMatch = matchedRoutesOnBeforeNavigate[matchedRoutesOnBeforeNavigate.length - 1];
const onBeforeNavigateRouteMatch =
onBeforeNavigateLastMatch?.routeId !== '__root__' ? onBeforeNavigateLastMatch : undefined;

const navigationLocation = WINDOW.location;
const navigationSpan = startBrowserTracingNavigationSpan(client, {
name: onBeforeNavigateLastMatch ? onBeforeNavigateLastMatch.routeId : navigationLocation.pathname,
name: onBeforeNavigateRouteMatch ? onBeforeNavigateRouteMatch.routeId : navigationLocation.pathname,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.solid.tanstack_router',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: onBeforeNavigateLastMatch ? 'route' : 'url',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: onBeforeNavigateRouteMatch ? 'route' : 'url',
},
});

// In case the user is redirected during navigation we want to update the span with the right value.
const unsubscribeOnResolved = router.subscribe('onResolved', onResolvedArgs => {
unsubscribeOnResolved();
if (navigationSpan) {
const onResolvedMatchedRoutes = router.matchRoutes(
const matchedRoutesOnResolved = router.matchRoutes(
onResolvedArgs.toLocation.pathname,
onResolvedArgs.toLocation.search,
{ preload: false, throwOnError: false },
);

const onResolvedLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1];
const onResolvedLastMatch = matchedRoutesOnResolved[matchedRoutesOnResolved.length - 1];
const onResolvedRouteMatch =
onResolvedLastMatch?.routeId !== '__root__' ? onResolvedLastMatch : undefined;

if (onResolvedLastMatch) {
navigationSpan.updateName(onResolvedLastMatch.routeId);
if (onResolvedRouteMatch) {
navigationSpan.updateName(onResolvedRouteMatch.routeId);
navigationSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
navigationSpan.setAttributes(routeMatchToParamSpanAttributes(onResolvedLastMatch));
navigationSpan.setAttributes(routeMatchToParamSpanAttributes(onResolvedRouteMatch));
}
}
});
Expand Down
26 changes: 16 additions & 10 deletions packages/vue/src/tanstackrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,22 @@ export function tanstackRouterBrowserTracingIntegration<R extends AnyRouter>(
if (instrumentPageLoad && initialWindowLocation) {
const matchedRoutes = router.matchRoutes(
initialWindowLocation.pathname,

router.options.parseSearch(initialWindowLocation.search),
{ preload: false, throwOnError: false },
);

const lastMatch = matchedRoutes[matchedRoutes.length - 1];
// If we only match __root__, we ended up not matching any route at all, so
// we fall back to the pathname.
const routeMatch = lastMatch?.routeId !== '__root__' ? lastMatch : undefined;

startBrowserTracingPageLoadSpan(client, {
name: lastMatch ? lastMatch.routeId : initialWindowLocation.pathname,
name: routeMatch ? routeMatch.routeId : initialWindowLocation.pathname,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.vue.tanstack_router',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: lastMatch ? 'route' : 'url',
...routeMatchToParamSpanAttributes(lastMatch),
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: routeMatch ? 'route' : 'url',
...routeMatchToParamSpanAttributes(routeMatch),
},
});
}
Expand Down Expand Up @@ -87,18 +89,20 @@ export function tanstackRouterBrowserTracingIntegration<R extends AnyRouter>(
);

const onBeforeNavigateLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1];
const onBeforeNavigateRouteMatch =
onBeforeNavigateLastMatch?.routeId !== '__root__' ? onBeforeNavigateLastMatch : undefined;

const navigationLocation = WINDOW.location;
const navigationSpan = startBrowserTracingNavigationSpan(client, {
name: onBeforeNavigateLastMatch
? onBeforeNavigateLastMatch.routeId
name: onBeforeNavigateRouteMatch
? onBeforeNavigateRouteMatch.routeId
: // In SSR/non-browser contexts, WINDOW.location may be undefined, so fall back to the router's location
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
navigationLocation?.pathname || onBeforeNavigateArgs.toLocation.pathname,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.vue.tanstack_router',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: onBeforeNavigateLastMatch ? 'route' : 'url',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: onBeforeNavigateRouteMatch ? 'route' : 'url',
},
});

Expand All @@ -116,11 +120,13 @@ export function tanstackRouterBrowserTracingIntegration<R extends AnyRouter>(
);

const onResolvedLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1];
const onResolvedRouteMatch =
onResolvedLastMatch?.routeId !== '__root__' ? onResolvedLastMatch : undefined;

if (onResolvedLastMatch) {
navigationSpan.updateName(onResolvedLastMatch.routeId);
if (onResolvedRouteMatch) {
navigationSpan.updateName(onResolvedRouteMatch.routeId);
navigationSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
navigationSpan.setAttributes(routeMatchToParamSpanAttributes(onResolvedLastMatch));
navigationSpan.setAttributes(routeMatchToParamSpanAttributes(onResolvedRouteMatch));
}
}
});
Expand Down
Loading