Skip to content

Commit 1c1f52b

Browse files
authored
feat: sentry integration (#641)
* feat: sentry integration * fix: netlify build command * set --import node_options * revert * test error * Revert "test error" This reverts commit f25daa3. * feat: import instrument.server.mjs in server entry point
1 parent 9ded5f7 commit 1c1f52b

File tree

8 files changed

+775
-187
lines changed

8 files changed

+775
-187
lines changed

netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
NODE_OPTIONS = "--max-old-space-size=4096"
33

44
[build]
5-
command = "vite build"
5+
command = "vite build && cp src/instrument.server.mjs dist/server"
66
publish = "dist/client"
77

88
[functions]

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dev": "pnpm run with-env vite dev",
1010
"with-env": "dotenv -e ../../.env",
1111
"dev:frontend": "pnpm run with-env vite dev",
12-
"build": "vite build",
12+
"build": "vite build && cp src/instrument.server.mjs dist/server",
1313
"start": "vite start",
1414
"lint": "eslint --ext .ts,.tsx ./src",
1515
"format": "prettier --experimental-cli --ignore-unknown '**/*' --write",
@@ -37,8 +37,8 @@
3737
"@radix-ui/react-toast": "^1.2.2",
3838
"@react-three/drei": "^10.7.7",
3939
"@react-three/fiber": "^9.5.0",
40-
"@sentry/react": "^8.35.0",
41-
"@sentry/vite-plugin": "^2.22.6",
40+
"@sentry/tanstackstart-react": "^10.32.1",
41+
"@sentry/vite-plugin": "^4.6.1",
4242
"@tailwindcss/typography": "^0.5.13",
4343
"@tailwindcss/vite": "^4.1.11",
4444
"@tanstack/pacer": "^0.16.4",

pnpm-lock.yaml

Lines changed: 726 additions & 167 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/DefaultCatchBoundary.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import {
66
useMatch,
77
useRouter,
88
} from '@tanstack/react-router'
9+
import * as Sentry from '@sentry/tanstackstart-react'
10+
911
import { Button } from './Button'
12+
import { useEffect } from 'react'
1013

1114
// type DefaultCatchBoundaryType = {
1215
// status: number
@@ -17,6 +20,9 @@ import { Button } from './Button'
1720

1821
export function DefaultCatchBoundary({ error }: ErrorComponentProps) {
1922
const router = useRouter()
23+
useEffect(() => {
24+
Sentry.captureException(error)
25+
}, [error])
2026
const isRoot = useMatch({
2127
strict: false,
2228
select: (state) => state.id === rootRouteId,

src/instrument.server.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as Sentry from '@sentry/tanstackstart-react'
2+
3+
Sentry.init({
4+
dsn: 'https://ac4bfc43ff4a892f8dc7053c4a50d92f@o4507236158537728.ingest.us.sentry.io/4507236163649536',
5+
integrations: [],
6+
sendDefaultPii: true,
7+
// Performance Monitoring
8+
tracesSampleRate: 1.0, // Capture 100% of the transactions
9+
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
10+
tracePropagationTargets: ['localhost', /^https:\/\/tanstack\.com\//],
11+
})

src/router.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DefaultCatchBoundary } from './components/DefaultCatchBoundary'
55
import { NotFound } from './components/NotFound'
66
import { QueryClient } from '@tanstack/react-query'
77
import { GamOnPageChange } from './components/Gam'
8+
import * as Sentry from '@sentry/tanstackstart-react'
89

910
export function getRouter() {
1011
const queryClient: QueryClient = new QueryClient({
@@ -42,6 +43,24 @@ export function getRouter() {
4243
GamOnPageChange()
4344
})
4445

46+
if (!router.isServer) {
47+
Sentry.init({
48+
dsn: 'https://ac4bfc43ff4a892f8dc7053c4a50d92f@o4507236158537728.ingest.us.sentry.io/4507236163649536',
49+
integrations: [
50+
Sentry.browserTracingIntegration(),
51+
Sentry.replayIntegration(),
52+
],
53+
sendDefaultPii: true,
54+
// Performance Monitoring
55+
tracesSampleRate: 1.0, // Capture 100% of the transactions
56+
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
57+
tracePropagationTargets: ['localhost', /^https:\/\/tanstack\.com\//],
58+
// Session Replay
59+
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.
60+
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
61+
})
62+
}
63+
4564
return router
4665
}
4766

src/server.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import './instrument.server.mjs'
2+
3+
import handler, { createServerEntry } from '@tanstack/react-start/server-entry'
4+
5+
export default createServerEntry({
6+
fetch(request) {
7+
return handler.fetch(request)
8+
},
9+
})

src/utils/sentry.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)