Skip to content

Commit f54c2a8

Browse files
authored
docs: add sentry to website for error reporting (#1496)
1 parent eb52684 commit f54c2a8

12 files changed

+1693
-9651
lines changed

docs/.env.local.example

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
AUTH_SECRET= # Linux: `openssl rand -hex 32` or go to https://generate-secret.vercel.app/32
22

33
AUTH_GITHUB_ID=
4-
AUTH_GITHUB_SECRET=
4+
AUTH_GITHUB_SECRET=
5+
6+
# The SENTRY_AUTH_TOKEN variable is picked up by the Sentry Build Plugin.
7+
# It's used for authentication when uploading source maps.
8+
SENTRY_AUTH_TOKEN=

docs/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ yarn-error.log*
3434
# typescript
3535
*.tsbuildinfo
3636
next-env.d.ts
37+
38+
# Sentry Config File
39+
.env.sentry-build-plugin

docs/app/global-error.tsx

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use client";
2+
3+
import * as Sentry from "@sentry/nextjs";
4+
import NextError from "next/error";
5+
import { useEffect } from "react";
6+
7+
export default function GlobalError({ error }: { error: Error & { digest?: string } }) {
8+
useEffect(() => {
9+
Sentry.captureException(error);
10+
}, [error]);
11+
12+
return (
13+
<html>
14+
<body>
15+
{/* `NextError` is the default Next.js error page component. Its type
16+
definition requires a `statusCode` prop. However, since the App Router
17+
does not expose status codes for errors, we simply pass 0 to render a
18+
generic error message. */}
19+
<NextError statusCode={0} />
20+
</body>
21+
</html>
22+
);
23+
}

docs/instrumentation.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
export async function register() {
4+
if (process.env.NEXT_RUNTIME === 'nodejs') {
5+
await import('./sentry.server.config');
6+
}
7+
8+
if (process.env.NEXT_RUNTIME === 'edge') {
9+
await import('./sentry.edge.config');
10+
}
11+
}
12+
13+
export const onRequestError = Sentry.captureRequestError;

docs/next.config.mjs

+43-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { withSentryConfig } from "@sentry/nextjs";
12
/** @type {import('next').NextConfig} */
23
import analyzer from "@next/bundle-analyzer";
34
import nextra from "nextra";
4-
import path from "path";
5-
import { fileURLToPath } from "url";
5+
// import path from "path";
6+
// import { fileURLToPath } from "url";
67

7-
const __filename = fileURLToPath(import.meta.url);
8-
const __dirname = path.dirname(__filename);
8+
// const __filename = fileURLToPath(import.meta.url);
9+
// const __dirname = path.dirname(__filename);
910

1011
const withNextra = nextra({
1112
theme: "nextra-theme-docs",
@@ -132,7 +133,7 @@ const nextConfig = withAnalyzer(
132133
experimental: {
133134
externalDir: true,
134135
},
135-
webpack: (config, { isServer }) => {
136+
webpack: (config) => {
136137
config.externals.push({
137138
// "@blocknote/core": "bncore",
138139
// "@blocknote/react": "bnreact",
@@ -183,4 +184,40 @@ const nextConfig = withAnalyzer(
183184
}),
184185
);
185186

186-
export default nextConfig;
187+
export default withSentryConfig(nextConfig, {
188+
// For all available options, see:
189+
// https://www.npmjs.com/package/@sentry/webpack-plugin#options
190+
191+
org: "blocknote-js",
192+
project: "website",
193+
194+
// Only print logs for uploading source maps in CI
195+
silent: !process.env.CI,
196+
197+
// For all available options, see:
198+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
199+
200+
// Upload a larger set of source maps for prettier stack traces (increases build time)
201+
widenClientFileUpload: true,
202+
203+
// Automatically annotate React components to show their full name in breadcrumbs and session replay
204+
reactComponentAnnotation: {
205+
enabled: true,
206+
},
207+
208+
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
209+
// This can increase your server load as well as your hosting bill.
210+
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
211+
// side errors will fail.
212+
tunnelRoute: "/monitoring",
213+
214+
// Automatically tree-shake Sentry logger statements to reduce bundle size
215+
disableLogger: true,
216+
217+
// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
218+
// See the following for more information:
219+
// https://docs.sentry.io/product/crons/
220+
// https://vercel.com/docs/cron-jobs
221+
automaticVercelMonitors: true,
222+
telemetry: false,
223+
});

0 commit comments

Comments
 (0)