Skip to content

Integrate Sentry error monitoring and remove Discord webhook alerts - #314

Draft
owens1127 with Copilot wants to merge 3 commits into
mainfrom
copilot/integrate-sentry-error-monitoring
Draft

Integrate Sentry error monitoring and remove Discord webhook alerts#314
owens1127 with Copilot wants to merge 3 commits into
mainfrom
copilot/integrate-sentry-error-monitoring

Conversation

Copilot AI commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Replaces Discord webhook-based error alerting with Sentry for comprehensive error monitoring across client, server, edge, and API layers.

Implementation

Configuration & Instrumentation

  • Created runtime-specific Sentry configs (sentry.server.config.ts, sentry.edge.config.ts) and instrumentation hooks (src/instrumentation.ts, src/instrumentation-client.ts)
  • Wrapped Next.js config with withSentryConfig, enabling source map uploads, tunnel route (/monitoring), and Vercel monitors integration
  • Client config includes session replay (10% baseline, 100% on errors) and router transition tracking

Error Capture Points

  • Error boundaries (global-error.tsx, error.tsx) now call Sentry.captureException()
  • tRPC error handler captures exceptions with scoped context (path, input, source) via Sentry.withScope()
  • NextAuth logger error callback captures auth flow exceptions

Removed

  • Discord webhook integration from tRPC error handler (sendDiscordWebhook, 50+ lines of embed formatting)

Example

// Before: tRPC errors sent to Discord webhook
if (process.env.NODE_ENV === "production" && process.env.TRPC_ALERTS_WEBHOOK_URL) {
    await sendDiscordWebhook(url, { embeds: [...] })
}

// After: tRPC errors sent to Sentry with structured context
Sentry.withScope(scope => {
    scope.setContext("trpc", { path, input, source })
    Sentry.captureException(error)
})

Environment Variables Required

NEXT_PUBLIC_SENTRY_DSN       # Client & server DSN
SENTRY_ORG, SENTRY_PROJECT   # Source map uploads
SENTRY_AUTH_TOKEN            # Build-time auth
APP_ENV                      # Environment identifier

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint.prisma.io
    • Triggering command: /opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node /home/REDACTED/work/Web-App/Web-App/node_modules/prisma/build/child {"product":"prisma","version":"6.5.0","cli_install_type":"local","information":"","local_timestamp":"2026-02-06T05:41:06Z","project_hash":"e746e93b","cli_path":"/home/REDACTED/work/Web-App/Web-App/node_modules/.bin/prisma","cli_path_hash":"d1777587","endpoi (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node /home/REDACTED/work/Web-App/Web-App/node_modules/prisma/build/child {"product":"prisma","version":"6.5.0","cli_install_type":"local","information":"","local_timestamp":"2026-02-06T05:41:07Z","project_hash":"e746e93b","cli_path":"/home/REDACTED/work/Web-App/Web-App/node_modules/.bin/prisma","cli_path_hash":"d1777587","endpoi (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Overview

Integrate Sentry for comprehensive error monitoring across the entire Next.js App Router application. The app currently relies on console.error and Discord webhooks for error visibility. Sentry should be added to capture errors from the client-side, server-side, API routes (tRPC), and auth flows.

Codebase Context

This is a Next.js App Router project using:

  • bun as the package manager (see package.json scripts)
  • tRPC for API routes (served at /api/trpc/[trpc]/route.ts)
  • NextAuth for authentication (served at /api/auth/[...nextauth]/route.ts)
  • Vercel for deployment (uses VERCEL_URL, DEPLOY_URL env vars)
  • The project uses next.config.js (CommonJS) with @next/bundle-analyzer

Key Files to Modify

  1. package.json — Add @sentry/nextjs as a dependency.

  2. next.config.js — Wrap the existing config with withSentryConfig from @sentry/nextjs. Preserve the existing withBundleAnalyzer wrapper and all other config. Use withSentryConfig as the outermost wrapper. Configure Sentry webpack plugin options including:

    • org and project should read from process.env.SENTRY_ORG and process.env.SENTRY_PROJECT
    • silent: !process.env.CI (only log in CI)
    • Enable widenClientFileUpload, tunnelRoute (use /monitoring), hideSourceMaps, disableLogger, and automaticVercelMonitors
  3. src/instrumentation.ts — Create a new Next.js instrumentation file that calls Sentry.init for the server (Node.js) runtime. This is the recommended way to initialize Sentry on the server in Next.js App Router. Import from the appropriate Sentry config file.

  4. src/instrumentation-client.ts — Create a new Next.js client instrumentation file that calls Sentry.init for the browser runtime. Configure:

    • dsn from process.env.NEXT_PUBLIC_SENTRY_DSN
    • tracesSampleRate: 1.0
    • replaysSessionSampleRate: 0.1
    • replaysOnErrorSampleRate: 1.0
    • Include Sentry.replayIntegration()
    • Set environment based on process.env.NEXT_PUBLIC_APP_ENV ?? "development"
  5. sentry.server.config.ts — Create a Sentry server config file:

    • dsn from process.env.NEXT_PUBLIC_SENTRY_DSN
    • tracesSampleRate: 1.0
    • Set environment based on process.env.APP_ENV ?? "development"
  6. sentry.edge.config.ts — Create a Sentry edge config file with the same settings as server config (for edge runtime API routes like the Ko-fi webhook at src/app/api/webhooks/kofi/route.ts).

  7. src/app/global-error.tsx — Update the existing global error boundary to capture exceptions with Sentry. Currently it only does console.error(error). It should:

    • Call Sentry.captureException(error) in the useEffect
    • Keep the existing UI

    Current file:

    "use client"
    import { useEffect } from "react"
    import { PageWrapper } from "~/components/PageWrapper"
    export default function GlobalError({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) {
        useEffect(() => { console.error(error) }, [error])
        return (<html><body><PageWrapper><h2>Something went wrong!</h2><button onClick={() => reset()}>Try again</button></PageWrapper></body></html>)
    }
  8. src/app/error.tsx — Update the existing error boundary to capture exceptions with Sentry. Currently it only does console.error(err). It should:

    • Call Sentry.captureException(error) in the useEffect (alongside the existing console.error)
    • Keep the existing UI and metadata logging

    Current file:

    "use client"
    import { useParams, usePathname, useSearchParams } from "next/navigation"
    import { useEffect } from "react"
    import { type ErrorBoundaryProps } from "~/types/generic"
    export default function ErrorBoundary({ error, reset }: ErrorBoundaryProps) {
        const pathname = usePathname()
        const params = useParams()
        const searchParams = useSearchParams()
        useEffect(() => {
            const err = { next: { pathname, params, searchParams: searchParams.toString() }, error: { className: error.constructor.name, message: error.message, stack: error.stack } }
            console.error(err)
        }, [error, params, pathname, searchParams])
        return (<div><h2>Something went wrong!</h2><button onClick={() => reset()}>Try again</button><button onClick={() => window.location.reload()}>Hard reload</button><pre>{JSON.stringify(error, null, 2)}</pre></div>)
    }
  9. src/lib/server/trpc/error-handler.ts — Add Sentry.captureException(error) to the tRPC error handler, alongside the existing Discord webhook notification. Import Sentry with import * as Sentry from "@sentry/nextjs". Call Sentry.captureException with extra context (path, input, source) set via Sentry.setContext or Sentry.withScope. This should happen unconditionally (not gated behind production check like the Discord webhook).

    Current file:

    
    

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel

vercel Bot commented Feb 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
raid-hub Error Error Feb 6, 2026 5:44am

Request Review

Co-authored-by: owens1127 <98496129+owens1127@users.noreply.github.com>
Co-authored-by: owens1127 <98496129+owens1127@users.noreply.github.com>
Copilot AI changed the title [WIP] Integrate Sentry for error monitoring in Next.js app Integrate Sentry error monitoring and remove Discord webhook alerts Feb 6, 2026
Copilot AI requested a review from owens1127 February 6, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants