Skip to content

Instrument with Sentry changes #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ ENCRYPTION_SECRET="some-made-up-secret"
INTERNAL_COMMAND_TOKEN="some-made-up-token"
MAILGUN_DOMAIN="mg.example.com"
MAILGUN_SENDING_KEY="some-api-token-with-dashes"
SENTRY_DSN=""
32 changes: 30 additions & 2 deletions app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
import { RemixBrowser } from '@remix-run/react'
import { startTransition } from 'react'
import { RemixBrowser, useLocation, useMatches } from '@remix-run/react'
import * as Sentry from '@sentry/remix'
import { startTransition, useEffect } from 'react'
import { hydrateRoot } from 'react-dom/client'

Sentry.init({
dsn: ENV.SENTRY_DSN,
integrations: [
new Sentry.BrowserTracing({
// Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled
tracePropagationTargets: ['localhost'],
routingInstrumentation: Sentry.remixRouterInstrumentation(
useEffect,
useLocation,
useMatches,
),
}),
// Replay is only available in the client
new Sentry.Replay(),
],

// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,

// Capture Replay for 10% of all sessions,
// plus for 100% of sessions with an error
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
})

if (ENV.MODE === 'development') {
import('~/utils/devtools.tsx').then(({ init }) => init())
}
Expand Down
9 changes: 9 additions & 0 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Response, 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 All @@ -12,6 +13,14 @@ const ABORT_DELAY = 5000
init()
global.ENV = getEnv()

Sentry.init({
dsn: ENV.SENTRY_DSN,
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
})

type DocRequestArgs = Parameters<HandleDocumentRequestFunction>

export default async function handleRequest(...args: DocRequestArgs) {
Expand Down
5 changes: 4 additions & 1 deletion app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
useLoaderData,
useSubmit,
} from '@remix-run/react'
import { withSentry } from '@sentry/remix'
import { clsx } from 'clsx'
import { useState } from 'react'
import tailwindStylesheetUrl from './styles/tailwind.css'
Expand Down Expand Up @@ -84,7 +85,7 @@ export async function loader({ request }: DataFunctionArgs) {
return json({ user, ENV: getEnv() })
}

export default function App() {
function App() {
const data = useLoaderData<typeof loader>()
const nonce = useNonce()
const { user } = data
Expand Down Expand Up @@ -141,6 +142,8 @@ export default function App() {
)
}

export default withSentry(App)

function ThemeSwitch() {
const fetcher = useFetcher()
const [mode, setMode] = useState<'system' | 'dark' | 'light'>('system')
Expand Down
2 changes: 2 additions & 0 deletions app/utils/env.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ export function init() {
*/
export function getEnv() {
invariant(process.env.NODE_ENV, 'NODE_ENV should be defined')
invariant(process.env.SENTRY_DSN, 'SENTRY_DSN should be defined')

return {
MODE: process.env.NODE_ENV,
SENTRY_DSN: process.env.SENTRY_DSN,
}
}

Expand Down
Loading