@@ -10,23 +10,22 @@ import {
1010 SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
1111 SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
1212} from '@sentry/core' ;
13- import type { VendoredTanstackRouter , VendoredTanstackRouterRouteMatch } from './vendor/tanstackrouter-types' ;
13+ import type { AnyRouter } from '@tanstack/solid-router' ;
14+
15+ type RouteMatch = ReturnType < AnyRouter [ 'matchRoutes' ] > [ number ] ;
1416
1517/**
1618 * A custom browser tracing integration for TanStack Router.
1719 *
18- * The minimum compatible version of `@tanstack/solid-router` is `1.64.0`.
20+ * The minimum compatible version of `@tanstack/solid-router` is `1.64.0
1921 *
2022 * @param router A TanStack Router `Router` instance that should be used for routing instrumentation.
2123 * @param options Sentry browser tracing configuration.
2224 */
23- export function tanstackRouterBrowserTracingIntegration (
24- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25- router : any , // This is `any` because we don't want any type mismatches if TanStack Router changes their types
25+ export function tanstackRouterBrowserTracingIntegration < R extends AnyRouter > (
26+ router : R ,
2627 options : Parameters < typeof originalBrowserTracingIntegration > [ 0 ] = { } ,
2728) : Integration {
28- const castRouterInstance : VendoredTanstackRouter = router ;
29-
3029 const browserTracingIntegrationInstance = originalBrowserTracingIntegration ( {
3130 ...options ,
3231 instrumentNavigation : false ,
@@ -42,9 +41,9 @@ export function tanstackRouterBrowserTracingIntegration(
4241
4342 const initialWindowLocation = WINDOW . location ;
4443 if ( instrumentPageLoad && initialWindowLocation ) {
45- const matchedRoutes = castRouterInstance . matchRoutes (
44+ const matchedRoutes = router . matchRoutes (
4645 initialWindowLocation . pathname ,
47- castRouterInstance . options . parseSearch ( initialWindowLocation . search ) ,
46+ router . options . parseSearch ( initialWindowLocation . search ) ,
4847 { preload : false , throwOnError : false } ,
4948 ) ;
5049
@@ -63,13 +62,13 @@ export function tanstackRouterBrowserTracingIntegration(
6362
6463 if ( instrumentNavigation ) {
6564 // The onBeforeNavigate hook is called at the very beginning of a navigation and is only called once per navigation, even when the user is redirected
66- castRouterInstance . subscribe ( 'onBeforeNavigate' , onBeforeNavigateArgs => {
65+ router . subscribe ( 'onBeforeNavigate' , onBeforeNavigateArgs => {
6766 // onBeforeNavigate is called during pageloads. We can avoid creating navigation spans by comparing the states of the to and from arguments.
6867 if ( onBeforeNavigateArgs . toLocation . state === onBeforeNavigateArgs . fromLocation ?. state ) {
6968 return ;
7069 }
7170
72- const onResolvedMatchedRoutes = castRouterInstance . matchRoutes (
71+ const onResolvedMatchedRoutes = router . matchRoutes (
7372 onBeforeNavigateArgs . toLocation . pathname ,
7473 onBeforeNavigateArgs . toLocation . search ,
7574 { preload : false , throwOnError : false } ,
@@ -88,10 +87,10 @@ export function tanstackRouterBrowserTracingIntegration(
8887 } ) ;
8988
9089 // In case the user is redirected during navigation we want to update the span with the right value.
91- const unsubscribeOnResolved = castRouterInstance . subscribe ( 'onResolved' , onResolvedArgs => {
90+ const unsubscribeOnResolved = router . subscribe ( 'onResolved' , onResolvedArgs => {
9291 unsubscribeOnResolved ( ) ;
9392 if ( navigationSpan ) {
94- const onResolvedMatchedRoutes = castRouterInstance . matchRoutes (
93+ const onResolvedMatchedRoutes = router . matchRoutes (
9594 onResolvedArgs . toLocation . pathname ,
9695 onResolvedArgs . toLocation . search ,
9796 { preload : false , throwOnError : false } ,
@@ -112,14 +111,13 @@ export function tanstackRouterBrowserTracingIntegration(
112111 } ;
113112}
114113
115- function routeMatchToParamSpanAttributes ( match : VendoredTanstackRouterRouteMatch | undefined ) : Record < string , string > {
114+ function routeMatchToParamSpanAttributes ( match : RouteMatch | undefined ) : Record < string , string > {
116115 if ( ! match ) {
117116 return { } ;
118117 }
119118
120119 const paramAttributes : Record < string , string > = { } ;
121- Object . entries ( match . params ) . forEach ( ( [ key , value ] ) => {
122- paramAttributes [ `url.path.params.${ key } ` ] = value ; // TODO(v11): remove attribute which does not adhere to Sentry's semantic convention
120+ Object . entries ( match . params as Record < string , string > ) . forEach ( ( [ key , value ] ) => {
123121 paramAttributes [ `url.path.parameter.${ key } ` ] = value ;
124122 paramAttributes [ `params.${ key } ` ] = value ; // params.[key] is an alias
125123 } ) ;
0 commit comments