Skip to content

Commit b78978e

Browse files
authored
update sentry (#961)
1 parent d30802a commit b78978e

9 files changed

+356
-379
lines changed

app/components/error-boundary.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { captureException } from '@sentry/react'
1+
import { captureException } from '@sentry/react-router'
22
import { useEffect, type ReactElement } from 'react'
33
import {
44
type ErrorResponse,

app/entry.server.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PassThrough } from 'node:stream'
33
import { styleText } from 'node:util'
44
import { contentSecurity } from '@nichtsam/helmet/content'
55
import { createReadableStreamFromReadable } from '@react-router/node'
6-
import * as Sentry from '@sentry/node'
6+
import * as Sentry from '@sentry/react-router'
77
import { isbot } from 'isbot'
88
import { renderToPipeableStream } from 'react-dom/server'
99
import {
@@ -131,11 +131,12 @@ export function handleError(
131131
if (request.signal.aborted) {
132132
return
133133
}
134+
134135
if (error instanceof Error) {
135136
console.error(styleText('red', String(error.stack)))
136-
void Sentry.captureException(error)
137137
} else {
138138
console.error(error)
139-
Sentry.captureException(error)
140139
}
140+
141+
Sentry.captureException(error)
141142
}

app/utils/monitoring.client.tsx

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import * as Sentry from '@sentry/react'
2-
import React from 'react'
3-
import {
4-
createRoutesFromChildren,
5-
matchRoutes,
6-
useLocation,
7-
useNavigationType,
8-
} from 'react-router'
1+
import * as Sentry from '@sentry/react-router'
92

103
export function init() {
114
Sentry.init({
@@ -27,13 +20,6 @@ export function init() {
2720
integrations: [
2821
Sentry.replayIntegration(),
2922
Sentry.browserProfilingIntegration(),
30-
Sentry.reactRouterV7BrowserTracingIntegration({
31-
useEffect: React.useEffect,
32-
useLocation,
33-
useNavigationType,
34-
createRoutesFromChildren,
35-
matchRoutes,
36-
}),
3723
],
3824

3925
// Set tracesSampleRate to 1.0 to capture 100%

package-lock.json

+303-329
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@
6767
"@react-router/node": "^7.2.0",
6868
"@react-router/remix-routes-option-adapter": "^7.2.0",
6969
"@remix-run/server-runtime": "^2.15.3",
70-
"@sentry/node": "^9.2.0",
71-
"@sentry/profiling-node": "^9.2.0",
72-
"@sentry/react": "^9.2.0",
70+
"@sentry/profiling-node": "9.5.0",
71+
"@sentry/react-router": "9.5.0",
7372
"@simplewebauthn/browser": "^13.1.0",
7473
"@simplewebauthn/server": "^13.1.1",
7574
"@tusbar/cache-control": "1.0.2",
@@ -122,7 +121,6 @@
122121
"@faker-js/faker": "^9.5.0",
123122
"@playwright/test": "^1.50.1",
124123
"@react-router/dev": "^7.2.0",
125-
"@sentry/vite-plugin": "^3.2.1",
126124
"@sly-cli/sly": "^1.14.0",
127125
"@testing-library/dom": "^10.4.0",
128126
"@testing-library/jest-dom": "^6.6.3",

react-router.config.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
import { type Config } from '@react-router/dev/config'
2+
import { sentryOnBuildEnd } from '@sentry/react-router'
3+
4+
const MODE = process.env.NODE_ENV
5+
26
export default {
37
// Defaults to true. Set to false to enable SPA for all routes.
48
ssr: true,
59

610
future: {
711
unstable_optimizeDeps: true,
812
},
13+
14+
buildEnd: async ({ viteConfig, reactRouterConfig, buildManifest }) => {
15+
if (MODE === 'production' && process.env.SENTRY_AUTH_TOKEN) {
16+
await sentryOnBuildEnd({
17+
viteConfig,
18+
reactRouterConfig,
19+
buildManifest,
20+
})
21+
}
22+
},
923
} satisfies Config

server/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { styleText } from 'node:util'
22
import { helmet } from '@nichtsam/helmet/node-http'
33
import { createRequestHandler } from '@react-router/express'
4-
import * as Sentry from '@sentry/node'
4+
import * as Sentry from '@sentry/react-router'
55
import { ip as ipAddress } from 'address'
66
import closeWithGrace from 'close-with-grace'
77
import compression from 'compression'

server/utils/monitoring.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import prismaInstrumentation from '@prisma/instrumentation'
2-
import * as Sentry from '@sentry/node'
32
import { nodeProfilingIntegration } from '@sentry/profiling-node'
3+
import * as Sentry from '@sentry/react-router'
44

55
// prisma's exports are wrong...
66
// https://github.com/prisma/prisma/issues/23410

vite.config.ts

+29-25
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { reactRouter } from '@react-router/dev/vite'
2-
import { sentryVitePlugin } from '@sentry/vite-plugin'
3-
2+
import {
3+
sentryReactRouter,
4+
type SentryReactRouterBuildOptions,
5+
} from '@sentry/react-router'
6+
import { defineConfig } from 'vite'
47
import { envOnlyMacros } from 'vite-env-only'
5-
import { type ViteUserConfig } from 'vitest/config'
68

79
const MODE = process.env.NODE_ENV
810

9-
export default {
11+
export default defineConfig((config) => ({
1012
build: {
1113
target: 'es2022',
1214
cssMinify: MODE === 'production',
@@ -32,30 +34,14 @@ export default {
3234
ignored: ['**/playwright-report/**'],
3335
},
3436
},
37+
sentryConfig,
3538
plugins: [
3639
envOnlyMacros(),
3740
// it would be really nice to have this enabled in tests, but we'll have to
3841
// wait until https://github.com/remix-run/remix/issues/9871 is fixed
39-
process.env.NODE_ENV === 'test' ? null : reactRouter(),
40-
process.env.SENTRY_AUTH_TOKEN
41-
? sentryVitePlugin({
42-
disable: MODE !== 'production',
43-
authToken: process.env.SENTRY_AUTH_TOKEN,
44-
org: process.env.SENTRY_ORG,
45-
project: process.env.SENTRY_PROJECT,
46-
release: {
47-
name: process.env.COMMIT_SHA,
48-
setCommits: {
49-
auto: true,
50-
},
51-
},
52-
sourcemaps: {
53-
filesToDeleteAfterUpload: [
54-
'./build/**/*.map',
55-
'.server-build/**/*.map',
56-
],
57-
},
58-
})
42+
MODE === 'test' ? null : reactRouter(),
43+
MODE === 'production' && process.env.SENTRY_AUTH_TOKEN
44+
? sentryReactRouter(sentryConfig, config)
5945
: null,
6046
],
6147
test: {
@@ -68,4 +54,22 @@ export default {
6854
all: true,
6955
},
7056
},
71-
} satisfies ViteUserConfig
57+
}))
58+
59+
const sentryConfig: SentryReactRouterBuildOptions = {
60+
authToken: process.env.SENTRY_AUTH_TOKEN,
61+
org: process.env.SENTRY_ORG,
62+
project: process.env.SENTRY_PROJECT,
63+
64+
unstable_sentryVitePluginOptions: {
65+
release: {
66+
name: process.env.COMMIT_SHA,
67+
setCommits: {
68+
auto: true,
69+
},
70+
},
71+
sourcemaps: {
72+
filesToDeleteAfterUpload: ['./build/**/*.map', '.server-build/**/*.map'],
73+
},
74+
},
75+
}

0 commit comments

Comments
 (0)