Skip to content

Commit

Permalink
add more sentry integration
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Nov 3, 2023
1 parent 6dac0c7 commit b81fa69
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/components/error-boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useParams,
useRouteError,
} from '@remix-run/react'
import { captureRemixErrorBoundaryError } from '@sentry/remix'
import { getErrorMessage } from '#app/utils/misc.tsx'

type StatusHandler = (info: {
Expand All @@ -25,6 +26,7 @@ export function GeneralErrorBoundary({
unexpectedErrorHandler?: (error: unknown) => JSX.Element | null
}) {
const error = useRouteError()
captureRemixErrorBoundaryError(error)
const params = useParams()

if (typeof document !== 'undefined') {
Expand Down
13 changes: 13 additions & 0 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { PassThrough } from 'stream'
import {
createReadableStreamFromReadable,
type DataFunctionArgs,
type HandleDocumentRequestFunction,
} from '@remix-run/node'
import { RemixServer } from '@remix-run/react'
import * as Sentry from '@sentry/remix'
import isbot from 'isbot'
import { getInstanceInfo } from 'litefs-js'
import { renderToPipeableStream } from 'react-dom/server'
Expand Down Expand Up @@ -89,3 +91,14 @@ export async function handleDataRequest(response: Response) {

return response
}

export function handleError(
error: unknown,
{ request }: DataFunctionArgs,
): void {
if (error instanceof Error) {
Sentry.captureRemixServerException(error, 'remix.server', request)
} else {
Sentry.captureException(error)
}
}
1 change: 1 addition & 0 deletions app/utils/monitoring.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useEffect } from 'react'
export function init() {
Sentry.init({
dsn: ENV.SENTRY_DSN,
environment: ENV.MODE,
integrations: [
new Sentry.BrowserTracing({
routingInstrumentation: Sentry.remixRouterInstrumentation(
Expand Down
5 changes: 3 additions & 2 deletions app/utils/monitoring.server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as Sentry from '@sentry/remix'
import { prisma } from './db.server.ts'

export function init() {
Sentry.init({
dsn: ENV.SENTRY_DSN,
environment: ENV.MODE,
tracesSampleRate: 1,
// TODO: Make this work with Prisma
// integrations: [new Sentry.Integrations.Prisma({ client: prisma })],
integrations: [new Sentry.Integrations.Prisma({ client: prisma })],
})
}

0 comments on commit b81fa69

Please sign in to comment.