chore(docs): add sentry monitoring (#35529)
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -138,3 +138,6 @@ gcloud.json
|
||||
.temp/cli-latest
|
||||
|
||||
.pnpm-store/*
|
||||
|
||||
# Sentry CLI config
|
||||
**/.sentryclirc
|
||||
|
||||
3
apps/docs/.gitignore
vendored
3
apps/docs/.gitignore
vendored
@@ -33,3 +33,6 @@ public/llms/
|
||||
|
||||
# Copied examples folder
|
||||
/examples/
|
||||
|
||||
# Sentry Config File
|
||||
.env.sentry-build-plugin
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as Sentry from '@sentry/nextjs'
|
||||
import { type DocumentNode, graphql, GraphQLError, parse, specifiedRules, validate } from 'graphql'
|
||||
import { createComplexityLimitRule } from 'graphql-validation-complexity'
|
||||
import { NextResponse } from 'next/server'
|
||||
@@ -93,10 +94,16 @@ export async function POST(request: Request): Promise<NextResponse> {
|
||||
console.error(error)
|
||||
|
||||
if (error instanceof ApiError) {
|
||||
if (!error.isUserError()) {
|
||||
Sentry.captureException(error)
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
errors: [{ message: error.isPrivate() ? 'Internal Server Error' : error.message }],
|
||||
})
|
||||
} else {
|
||||
Sentry.captureException(error)
|
||||
|
||||
return NextResponse.json({
|
||||
errors: [{ message: 'Internal Server Error' }],
|
||||
})
|
||||
|
||||
@@ -18,6 +18,10 @@ export class ApiError<Details extends ObjectOrNever = never> extends Error {
|
||||
return true
|
||||
}
|
||||
|
||||
isUserError() {
|
||||
return false
|
||||
}
|
||||
|
||||
statusCode() {
|
||||
return 500
|
||||
}
|
||||
@@ -32,6 +36,10 @@ export class InvalidRequestError<Details extends ObjectOrNever = never> extends
|
||||
return false
|
||||
}
|
||||
|
||||
isUserError() {
|
||||
return true
|
||||
}
|
||||
|
||||
statusCode() {
|
||||
return 400
|
||||
}
|
||||
|
||||
23
apps/docs/app/global-error.tsx
Normal file
23
apps/docs/app/global-error.tsx
Normal 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 & { 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>
|
||||
)
|
||||
}
|
||||
24
apps/docs/instrumentation-client.ts
Normal file
24
apps/docs/instrumentation-client.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// This file configures the initialization of Sentry on the client.
|
||||
// The added config here will be used whenever a users loads a page in their browser.
|
||||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
|
||||
|
||||
import * as Sentry from '@sentry/nextjs'
|
||||
import { IS_DEV } from './lib/constants'
|
||||
|
||||
Sentry.init({
|
||||
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
|
||||
|
||||
// Setting this option to true will print useful information to the console while you're setting up Sentry.
|
||||
debug: false,
|
||||
|
||||
ignoreErrors: [
|
||||
// [Charis 2025-05-05]
|
||||
// We should fix hydration problems but let's not make this a blocker for
|
||||
// now.
|
||||
/(?:text content does not match)|hydration|hydrating/i,
|
||||
// Error thrown if local infra is not running
|
||||
...(IS_DEV ? ['Failed to fetch (localhost:8000)'] : []),
|
||||
],
|
||||
})
|
||||
|
||||
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart
|
||||
13
apps/docs/instrumentation.ts
Normal file
13
apps/docs/instrumentation.ts
Normal 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
|
||||
@@ -1,11 +1,10 @@
|
||||
// @ts-check
|
||||
import configureBundleAnalyzer from '@next/bundle-analyzer'
|
||||
import nextMdx from '@next/mdx'
|
||||
import { withSentryConfig } from '@sentry/nextjs'
|
||||
import withYaml from 'next-plugin-yaml'
|
||||
import rehypeSlug from 'rehype-slug'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
|
||||
import configureBundleAnalyzer from '@next/bundle-analyzer'
|
||||
import withYaml from 'next-plugin-yaml'
|
||||
|
||||
import remotePatterns from './lib/remotePatterns.js'
|
||||
|
||||
const withBundleAnalyzer = configureBundleAnalyzer({
|
||||
@@ -22,7 +21,6 @@ const withMDX = nextMdx({
|
||||
})
|
||||
|
||||
/** @type {import('next').NextConfig} nextConfig */
|
||||
|
||||
const nextConfig = {
|
||||
assetPrefix: getAssetPrefix(),
|
||||
// Append the default value with md extensions
|
||||
@@ -173,7 +171,31 @@ const configExport = () => {
|
||||
return plugins.reduce((acc, next) => next(acc), nextConfig)
|
||||
}
|
||||
|
||||
export default configExport
|
||||
export default withSentryConfig(configExport, {
|
||||
// For all available options, see:
|
||||
// https://www.npmjs.com/package/@sentry/webpack-plugin#options
|
||||
|
||||
org: 'supabase',
|
||||
project: 'docs',
|
||||
|
||||
// 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,
|
||||
|
||||
// Uncomment to 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,
|
||||
})
|
||||
|
||||
function getAssetPrefix() {
|
||||
// If not force enabled, but not production env, disable CDN
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
"@octokit/plugin-paginate-graphql": "^4.0.0",
|
||||
"@radix-ui/react-accordion": "^1.1.2",
|
||||
"@radix-ui/react-collapsible": "^1.0.3",
|
||||
"@sentry/nextjs": "^9.15.0",
|
||||
"@supabase/supabase-js": "catalog:",
|
||||
"@tailwindcss/container-queries": "^0.1.1",
|
||||
"@tanstack/react-query": "^5.13.4",
|
||||
|
||||
13
apps/docs/sentry.edge.config.ts
Normal file
13
apps/docs/sentry.edge.config.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
// 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,
|
||||
|
||||
// Setting this option to true will print useful information to the console while you're setting up Sentry.
|
||||
debug: false,
|
||||
})
|
||||
12
apps/docs/sentry.server.config.ts
Normal file
12
apps/docs/sentry.server.config.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// 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,
|
||||
|
||||
// Setting this option to true will print useful information to the console while you're setting up Sentry.
|
||||
debug: false,
|
||||
})
|
||||
@@ -26,6 +26,7 @@
|
||||
"NEXT_PUBLIC_SITE_URL",
|
||||
"NEXT_PUBLIC_DEV_AUTH_PAGE",
|
||||
"NEXT_PUBLIC_IS_PLATFORM",
|
||||
"NEXT_PUBLIC_SENTRY_DSN",
|
||||
"NEXT_PUBLIC_VERCEL_ENV",
|
||||
"NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA",
|
||||
// These envs are used in the packages
|
||||
|
||||
902
pnpm-lock.yaml
generated
902
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user