Skip to content

Commit 0ac94a8

Browse files
authored
feat: sentry integration (#954)
* feat: add sentry WIP * feat: update sentry init * feat: remove unnecessary component * feat: remove vercel cron option * feat: update env variable names * feat: explicitly silent mode
1 parent 650b523 commit 0ac94a8

File tree

6 files changed

+2108
-89
lines changed

6 files changed

+2108
-89
lines changed

frontend/app/error.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
'use client'; // Error components must be Client Components
1+
"use client"; // Error components must be Client Components
22

3-
import Image from 'next/image';
4-
import Link from 'next/link';
3+
import * as Sentry from "@sentry/nextjs";
4+
import Image from "next/image";
5+
import Link from "next/link";
6+
import { useEffect } from "react";
57

6-
import icon from '@/assets/logo/icon.png';
8+
import icon from "@/assets/logo/icon.png";
9+
10+
export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) {
11+
useEffect(() => {
12+
Sentry.captureException(error);
13+
}, [error]);
714

8-
export default function Error({
9-
error,
10-
reset
11-
}: {
12-
error: Error & { digest?: string };
13-
reset: () => void;
14-
}) {
1515
return (
1616
<div className="flex flex-col items-center justify-center min-h-screen">
17-
<Link
18-
href={'/projects'}
19-
className="flex h-10 mb-8 items-center justify-center"
20-
>
17+
<Link href={"/projects"} className="flex h-10 mb-8 items-center justify-center">
2118
<Image alt="Laminar AI icon" src={icon} width={80} />
2219
</Link>
2320
<h1 className="mb-4 text-lg">Oops, something went wrong</h1>

frontend/instrumentation.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
// Yes, this file is called instrumentation.ts, but it's not actually used to instrument the app.
22
// Apparently, this is the suggested way to run startup hooks in Next.js:
33
// https://github.com/vercel/next.js/discussions/15341#discussioncomment-7091594
4+
import * as Sentry from "@sentry/nextjs";
45

56
export async function register() {
7+
if (process.env.NEXT_RUNTIME === "nodejs") {
8+
await import("./sentry.server.config.ts");
9+
}
10+
611
// prevent this from running in the edge runtime for the second time
712
if (process.env.NEXT_RUNTIME === "nodejs") {
813
const { Feature, isFeatureEnabled } = await import("@/lib/features/features.ts");
@@ -61,10 +66,18 @@ export async function register() {
6166
await clickhouseClient.exec({ query: statement });
6267
} catch (error) {
6368
if ((error as { type: string }).type === "DUPLICATE_COLUMN") {
64-
console.warn("[WARNING] Failed to apply ClickHouse statement:", statement, "because column already exists");
69+
console.warn(
70+
"[WARNING] Failed to apply ClickHouse statement:",
71+
statement,
72+
"because column already exists"
73+
);
6574
continue;
6675
} else if ((error as { type: string }).type === "TABLE_ALREADY_EXISTS") {
67-
console.warn("[WARNING] Failed to apply ClickHouse statement:", statement, "because table already exists");
76+
console.warn(
77+
"[WARNING] Failed to apply ClickHouse statement:",
78+
statement,
79+
"because table already exists"
80+
);
6881
continue;
6982
} else {
7083
throw error;
@@ -97,3 +110,5 @@ export async function register() {
97110
}
98111
}
99112
}
113+
114+
export const onRequestError = Sentry.captureRequestError;

frontend/next.config.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @type {import('next').NextConfig} */
22
const path = require("path");
3+
const { withSentryConfig } = require("@sentry/nextjs");
34

45
const nextConfig = {
56
reactStrictMode: false,
@@ -76,4 +77,32 @@ const nextConfig = {
7677
},
7778
};
7879

79-
module.exports = nextConfig;
80+
if (process.env.ENVIRONMENT === "PRODUCTION" && process.env.FRONTEND_SENTRY_DSN) {
81+
module.exports = withSentryConfig(nextConfig, {
82+
// For all available options, see:
83+
// https://www.npmjs.com/package/@sentry/webpack-plugin#options
84+
85+
org: process.env.SENTRY_ORG,
86+
project: process.env.FRONTEND_SENTRY_PROJECT,
87+
88+
// Only print logs for uploading source maps in CI
89+
silent: true,
90+
91+
// For all available options, see:
92+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
93+
94+
// Upload a larger set of source maps for prettier stack traces (increases build time)
95+
widenClientFileUpload: true,
96+
97+
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
98+
// This can increase your server load as well as your hosting bill.
99+
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
100+
// side errors will fail.
101+
tunnelRoute: "/monitoring",
102+
103+
// Automatically tree-shake Sentry logger statements to reduce bundle size
104+
disableLogger: true,
105+
});
106+
} else {
107+
module.exports = nextConfig;
108+
}

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"@radix-ui/react-tooltip": "^1.2.8",
6868
"@react-email/components": "^0.3.3",
6969
"@react-email/tailwind": "^1.2.2",
70+
"@sentry/nextjs": "^10.19.0",
7071
"@supabase/supabase-js": "2.49.4",
7172
"@tanstack/react-table": "^8.21.3",
7273
"@tanstack/react-virtual": "^3.13.12",

0 commit comments

Comments
 (0)