Skip to content

Commit b15d561

Browse files
fix: init sentry earlier (#764)
and only add the tracing plugin that needs access to the router later Co-authored-by: Sarah Gerrard <gerrardsarah@gmail.com>
1 parent c53067a commit b15d561

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/router.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ import { NotFound } from './components/NotFound'
66
import { QueryClient } from '@tanstack/react-query'
77
import * as Sentry from '@sentry/tanstackstart-react'
88

9+
if (typeof document !== 'undefined') {
10+
Sentry.init({
11+
dsn: 'https://ac4bfc43ff4a892f8dc7053c4a50d92f@o4507236158537728.ingest.us.sentry.io/4507236163649536',
12+
integrations: [Sentry.replayIntegration()],
13+
sendDefaultPii: true,
14+
// Performance Monitoring
15+
tracesSampleRate: 1.0, // Capture 100% of the transactions
16+
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
17+
tracePropagationTargets: ['localhost', /^https:\/\/tanstack\.com\//],
18+
// Session Replay
19+
replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
20+
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
21+
})
22+
}
23+
924
export function getRouter() {
1025
const queryClient: QueryClient = new QueryClient({
1126
defaultOptions: {
@@ -29,26 +44,15 @@ export function getRouter() {
2944
},
3045
scrollToTopSelectors: ['.scroll-to-top'],
3146
})
32-
setupRouterSsrQueryIntegration({ router, queryClient })
3347

3448
if (!router.isServer) {
35-
Sentry.init({
36-
dsn: 'https://ac4bfc43ff4a892f8dc7053c4a50d92f@o4507236158537728.ingest.us.sentry.io/4507236163649536',
37-
integrations: [
38-
Sentry.browserTracingIntegration(),
39-
Sentry.replayIntegration(),
40-
],
41-
sendDefaultPii: true,
42-
// Performance Monitoring
43-
tracesSampleRate: 1.0, // Capture 100% of the transactions
44-
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
45-
tracePropagationTargets: ['localhost', /^https:\/\/tanstack\.com\//],
46-
// Session Replay
47-
replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
48-
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
49-
})
49+
Sentry.addIntegration(
50+
Sentry.tanstackRouterBrowserTracingIntegration(router),
51+
)
5052
}
5153

54+
setupRouterSsrQueryIntegration({ router, queryClient })
55+
5256
return router
5357
}
5458

0 commit comments

Comments
 (0)