Skip to content

Commit

Permalink
docs: add sentry to website for error reporting (#1496)
Browse files Browse the repository at this point in the history
  • Loading branch information
nperez0111 authored Mar 5, 2025
1 parent eb52684 commit f54c2a8
Show file tree
Hide file tree
Showing 12 changed files with 1,693 additions and 9,651 deletions.
6 changes: 5 additions & 1 deletion docs/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
AUTH_SECRET= # Linux: `openssl rand -hex 32` or go to https://generate-secret.vercel.app/32

AUTH_GITHUB_ID=
AUTH_GITHUB_SECRET=
AUTH_GITHUB_SECRET=

# The SENTRY_AUTH_TOKEN variable is picked up by the Sentry Build Plugin.
# It's used for authentication when uploading source maps.
SENTRY_AUTH_TOKEN=
3 changes: 3 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# Sentry Config File
.env.sentry-build-plugin
23 changes: 23 additions & 0 deletions docs/app/global-error.tsx
Original file line number Diff line number Diff line change
@@ -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 & { digest?: string } }) {
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>
);
}
13 changes: 13 additions & 0 deletions docs/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -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;
49 changes: 43 additions & 6 deletions docs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { withSentryConfig } from "@sentry/nextjs";
/** @type {import('next').NextConfig} */
import analyzer from "@next/bundle-analyzer";
import nextra from "nextra";
import path from "path";
import { fileURLToPath } from "url";
// import path from "path";
// import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// const __filename = fileURLToPath(import.meta.url);
// const __dirname = path.dirname(__filename);

const withNextra = nextra({
theme: "nextra-theme-docs",
Expand Down Expand Up @@ -132,7 +133,7 @@ const nextConfig = withAnalyzer(
experimental: {
externalDir: true,
},
webpack: (config, { isServer }) => {
webpack: (config) => {
config.externals.push({
// "@blocknote/core": "bncore",
// "@blocknote/react": "bnreact",
Expand Down Expand Up @@ -183,4 +184,40 @@ const nextConfig = withAnalyzer(
}),
);

export default nextConfig;
export default withSentryConfig(nextConfig, {
// For all available options, see:
// https://www.npmjs.com/package/@sentry/webpack-plugin#options

org: "blocknote-js",
project: "website",

// Only print logs for uploading source maps in CI
silent: !process.env.CI,

// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,

// Automatically annotate React components to show their full name in breadcrumbs and session replay
reactComponentAnnotation: {
enabled: true,
},

// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
// This can increase your server load as well as your hosting bill.
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
// side errors will fail.
tunnelRoute: "/monitoring",

// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,

// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
// See the following for more information:
// https://docs.sentry.io/product/crons/
// https://vercel.com/docs/cron-jobs
automaticVercelMonitors: true,
telemetry: false,
});
Loading

0 comments on commit f54c2a8

Please sign in to comment.