feat: add sentry bug reporting

This commit is contained in:
Vasily Zubarev
2025-04-08 20:56:23 +02:00
parent ec72b45ed8
commit b47dc4b80a
10 changed files with 3090 additions and 164 deletions

View File

@@ -1,10 +1,17 @@
PORT=7331
SELF_HOSTED_MODE=false
DISABLE_SIGNUP=false
SELF_HOSTED_MODE=true
DISABLE_SIGNUP=true
UPLOAD_PATH="./data/uploads"
DATABASE_URL="postgresql://user@localhost:5432/taxhacker"
BETTER_AUTH_SECRET="random-secret-key"
# You can put it here or the app will ask you to enter it
OPENAI_API_KEY=""
# Auth Config
BETTER_AUTH_SECRET="random-secret-key" # please use any long random string here
# Resend Configuration (optional, use if you want to send emails)
RESEND_API_KEY=""
RESEND_AUDIENCE_ID=""
RESEND_FROM_EMAIL="TaxHacker <user@localhost>"

4
.gitignore vendored
View File

@@ -52,4 +52,6 @@ pgdata
*.sqlite
*.sqlite3
*.sqlite-journal
*.db-journal
*.db-journal
# Sentry Config File
.env.sentry-build-plugin

23
app/global-error.tsx Normal file
View File

@@ -0,0 +1,23 @@
"use client"
import * as Sentry from "@sentry/nextjs"
import NextError from "next/error"
import { useEffect } from "react"
export default function GlobalError({ error }: { error: Error }) {
useEffect(() => {
Sentry.captureException(error)
}, [error])
return (
<html>
<body>
{/* `NextError` is the default Next.js error page component. Its type
definition requires a `statusCode` prop. However, since the App Router
does not expose status codes for errors, we simply pass 0 to render a
generic error message. */}
<NextError statusCode={0} />
</body>
</html>
)
}

View File

@@ -0,0 +1,5 @@
import * as Sentry from "@sentry/nextjs"
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
})

13
instrumentation.ts Normal file
View File

@@ -0,0 +1,13 @@
import * as Sentry from '@sentry/nextjs';
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('./sentry.server.config');
}
if (process.env.NEXT_RUNTIME === 'edge') {
await import('./sentry.edge.config');
}
}
export const onRequestError = Sentry.captureRequestError;

View File

@@ -1,3 +1,4 @@
import { withSentryConfig } from "@sentry/nextjs"
import type { NextConfig } from "next"
const nextConfig: NextConfig = {
@@ -11,4 +12,15 @@ const nextConfig: NextConfig = {
},
}
export default nextConfig
const isSentryEnabled = process.env.NEXT_PUBLIC_SENTRY_DSN && process.env.SENTRY_ORG && process.env.SENTRY_PROJECT
export default isSentryEnabled
? withSentryConfig(nextConfig, {
silent: !process.env.CI,
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
disableLogger: true,
widenClientFileUpload: true,
tunnelRoute: "/monitoring",
})
: nextConfig

3146
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -12,7 +12,7 @@
"dependencies": {
"@fast-csv/format": "^5.0.2",
"@fast-csv/parse": "^5.0.2",
"@prisma/client": "^6.4.1",
"@prisma/client": "^6.6.0",
"@radix-ui/react-avatar": "^1.1.3",
"@radix-ui/react-checkbox": "^1.1.4",
"@radix-ui/react-collapsible": "^1.1.3",
@@ -24,6 +24,7 @@
"@radix-ui/react-separator": "^1.1.2",
"@radix-ui/react-slot": "^1.1.2",
"@radix-ui/react-tooltip": "^1.1.8",
"@sentry/nextjs": "^9.11.0",
"@types/sharp": "^0.31.1",
"better-auth": "^1.2.5",
"class-variance-authority": "^0.7.1",
@@ -35,7 +36,6 @@
"next-themes": "^0.4.4",
"openai": "^4.85.4",
"pdf2pic": "^3.1.4",
"prisma": "^6.5.0",
"react": "^19.0.0",
"react-day-picker": "^8.10.1",
"react-dom": "^19.0.0",
@@ -56,6 +56,7 @@
"eslint": "^9",
"eslint-config-next": "15.1.7",
"postcss": "^8",
"prisma": "^6.6.0",
"tailwindcss": "^3.4.1",
"typescript": "^5"
},

16
sentry.edge.config.ts Normal file
View File

@@ -0,0 +1,16 @@
// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).
// The config you add here will be used whenever one of the edge features is loaded.
// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import * as Sentry from "@sentry/nextjs"
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
})

15
sentry.server.config.ts Normal file
View File

@@ -0,0 +1,15 @@
// This file configures the initialization of Sentry on the server.
// The config you add here will be used whenever the server handles a request.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import * as Sentry from "@sentry/nextjs"
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
})