1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-04-26 04:45:22 -04:00

add sentry to investigate 500 errors

This commit is contained in:
Jake Jarvis 2025-03-04 15:46:50 -05:00
parent a73323ae8b
commit 8f946d50d8
Signed by: jake
SSH Key Fingerprint: SHA256:nCkvAjYA6XaSPUqc4TfbBQTpzr8Xj7ritg/sGInCdkc
11 changed files with 2013 additions and 22 deletions

3
.gitignore vendored
View File

@ -34,3 +34,6 @@ yarn.lock
# vercel
.vercel
# Sentry Config File
.env.sentry-build-plugin

23
app/global-error.tsx Normal file
View 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>
);
}

View File

@ -1,4 +1,3 @@
import { useId } from "react";
import { GoLock } from "react-icons/go";
import { rgba } from "polished";
import Link from "../components/Link";
@ -16,15 +15,15 @@ const ColorfulLink = ({
lightColor: string;
darkColor: string;
}) => {
const uniqueId = `Link_themed__${useId().replace(/\W/g, "")}`;
const uniqueId = `Link_themed__${lightColor.replace("#", "")}_${darkColor.replace("#", "")}`;
return (
<>
<Link id={uniqueId} {...rest}>
<Link className={uniqueId} {...rest}>
{children}
</Link>
<style>{`.${styles.page} #${uniqueId}{color:${lightColor};--colors-linkUnderline:${rgba(lightColor, 0.4)}}[data-theme="dark"] .${styles.page} #${uniqueId}{color:${darkColor};--colors-linkUnderline:${rgba(darkColor, 0.4)}}`}</style>
<style>{`.${styles.page} .${uniqueId}{--colors-link:${lightColor};--colors-linkUnderline:${rgba(lightColor, 0.4)}}[data-theme="dark"] .${styles.page} .${uniqueId}{--colors-link:${darkColor};--colors-linkUnderline:${rgba(darkColor, 0.4)}}`}</style>
</>
);
};
@ -278,8 +277,8 @@ export default function Page() {
href="https://bsky.app/profile/jarv.is"
rel="me"
title="Jake Jarvis on Bluesky"
lightColor="#0085FF"
darkColor="#208BFE"
lightColor="#0085ff"
darkColor="#208bfe"
>
Bluesky
</ColorfulLink>

13
instrumentation.ts Normal file
View 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;

View File

@ -19,5 +19,7 @@ export function middleware(request: NextRequest) {
export const config = {
// save compute time by skipping middleware for static and metadata files
matcher: ["/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|manifest.webmanifest).*)"],
matcher: [
"/((?!_next/static|_next/image|_vercel|_instrument|favicon.ico|sitemap.xml|robots.txt|manifest.webmanifest).*)",
],
};

View File

@ -1,6 +1,7 @@
import type { NextConfig } from "next";
import createMDX from "@next/mdx";
import createBundleAnalyzer from "@next/bundle-analyzer";
import { withSentryConfig } from "@sentry/nextjs";
import * as mdxPlugins from "./lib/helpers/remark-rehype-plugins";
const nextConfig: NextConfig = {
@ -155,4 +156,17 @@ const withMDX = createMDX({
},
});
export default withBundleAnalyzer(withMDX(nextConfig));
export default withSentryConfig(withBundleAnalyzer(withMDX(nextConfig)), {
// https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/build/
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
silent: !process.env.CI,
widenClientFileUpload: true,
autoInstrumentAppDirectory: true,
autoInstrumentMiddleware: false,
autoInstrumentServerFunctions: true,
tunnelRoute: "/_instrument/",
disableLogger: true,
automaticVercelMonitors: true,
telemetry: false,
});

View File

@ -28,6 +28,7 @@
"@octokit/graphql-schema": "^15.26.0",
"@prisma/client": "^6.4.1",
"@react-spring/web": "^9.7.5",
"@sentry/nextjs": "^9.3.0",
"@vercel/analytics": "^1.5.0",
"clsx": "^2.1.1",
"comma-number": "^2.1.0",

1929
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

11
sentry.client.config.ts Normal file
View File

@ -0,0 +1,11 @@
// This file configures the initialization of Sentry on the client.
// The config you add 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";
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN || process.env.SENTRY_DSN,
environment: process.env.NEXT_PUBLIC_VERCEL_ENV || process.env.NODE_ENV,
tracesSampleRate: 1,
});

12
sentry.edge.config.ts Normal file
View File

@ -0,0 +1,12 @@
// 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 || process.env.SENTRY_DSN,
environment: process.env.NEXT_PUBLIC_VERCEL_ENV || process.env.NODE_ENV,
tracesSampleRate: 1,
});

12
sentry.server.config.ts Normal file
View 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 || process.env.SENTRY_DSN,
environment: process.env.NEXT_PUBLIC_VERCEL_ENV || process.env.NODE_ENV,
tracesSampleRate: 1,
integrations: [Sentry.prismaIntegration()],
});