Skip to content

Commit 3d3f4ba

Browse files
authored
[Fix] Correcting Sentry integraiton (#24)
* Removing global-middleware.ts approach for sentry init * Using isomorphic function from tanstack start to init client and server, including TanStack sentry integrations
1 parent b63e750 commit 3d3f4ba

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed
Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { createRouter as createTanstackRouter } from '@tanstack/react-router'<% if (addOnEnabled.sentry) { %>
22
import * as Sentry from '@sentry/react'
3+
import * as SentryServer from '@sentry/node'
4+
import { createIsomorphicFn } from '@tanstack/start'
35
<% } %>
46

57
// Import the generated route tree
@@ -10,25 +12,40 @@ import './styles.css'
1012
// Create a new router instance
1113
export const createRouter = () => {
1214
const router = createTanstackRouter({ routeTree })
13-
<% if (addOnEnabled.sentry) { %>
14-
Sentry.init({
15-
dsn: import.meta.env.VITE_SENTRY_DSN,
16-
integrations: [Sentry.replayIntegration(), Sentry.tanstackRouterBrowserTracingIntegration(router)],
17-
18-
// Setting a sample rate is required for sending performance data.
19-
// We recommend adjusting this value in production, or using tracesSampler
20-
// for finer control.
21-
tracesSampleRate: 1.0,
22-
replaysSessionSampleRate: 1.0, // 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.
23-
replaysOnErrorSampleRate: 1.0,
24-
});
25-
<% } %>
26-
return router;
15+
return router
2716
}
2817

18+
const router = createRouter()
19+
20+
<% if (addOnEnabled.sentry) { %>
21+
createIsomorphicFn().server(() => {
22+
SentryServer.init({
23+
dsn: import.meta.env.VITE_SENTRY_DSN,
24+
tracesSampleRate: 1.0,
25+
profilesSampleRate: 1.0,
26+
})
27+
}).client(() => {
28+
Sentry.init({
29+
dsn: import.meta.env.VITE_SENTRY_DSN,
30+
integrations: [
31+
Sentry.replayIntegration({
32+
maskAllText: false,
33+
blockAllMedia: false,
34+
}),
35+
Sentry.tanstackRouterBrowserTracingIntegration(router),
36+
],
37+
tracesSampleRate: 1.0,
38+
replaysSessionSampleRate: 1.0,
39+
replaysOnErrorSampleRate: 1.0,
40+
})
41+
})()
42+
<% } %>
43+
44+
45+
2946
// Register the router instance for type safety
3047
declare module '@tanstack/react-router' {
3148
interface Register {
32-
router: ReturnType<typeof createRouter>
49+
router: router
3350
}
3451
}

0 commit comments

Comments
 (0)