Skip to content

Commit 06680ce

Browse files
committed
feat: add sentry's react router integration
1 parent 7d0834a commit 06680ce

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/renderer/src/components/common/ErrorView.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { tipcClient } from '@renderer/lib/client'
2+
import * as Sentry from '@sentry/react'
3+
import { useEffect } from 'react'
24
import { useRouteError } from 'react-router'
35

46
import { Button } from '../ui/button'
@@ -7,6 +9,9 @@ export default function ErrorView() {
79
const error = useRouteError() as { statusText: string; message: string }
810
console.error(error)
911

12+
useEffect(() => {
13+
Sentry.captureException(error)
14+
}, [error])
1015
return (
1116
<div className="flex h-screen flex-col items-center justify-center gap-5">
1217
<p className="text-xl">糟糕发生错误了😭</p>

src/renderer/src/initialize/sentry.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
import { API_URL, isDev, SENTRY_DSN } from '@renderer/lib/env'
22
import * as Sentry from '@sentry/react'
3+
import { useEffect } from 'react'
4+
import { createRoutesFromChildren, matchRoutes, useLocation, useNavigationType } from 'react-router'
35

46
export const initializeSentry = () => {
57
if (isDev) {
68
return
79
}
810
Sentry.init({
911
dsn: SENTRY_DSN,
10-
integrations: [Sentry.browserTracingIntegration(), Sentry.replayIntegration()],
12+
integrations: [
13+
Sentry.reactRouterV7BrowserTracingIntegration({
14+
useEffect,
15+
useLocation,
16+
useNavigationType,
17+
createRoutesFromChildren,
18+
matchRoutes,
19+
}),
20+
Sentry.replayIntegration({
21+
// NOTE: This will disable built-in masking. Only use this if your site has no sensitive data, or if you've already set up other options for masking or blocking relevant data, such as 'ignore', 'block', 'mask' and 'maskFn'.
22+
maskAllText: false,
23+
blockAllMedia: false,
24+
}),
25+
],
1126
// Tracing
1227
tracesSampleRate: 1, // Capture 100% of the transactions
1328
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled

0 commit comments

Comments
 (0)