Skip to content

Commit

Permalink
chore: added sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
FleetAdmiralJakob committed Nov 27, 2024
1 parent 18e45e1 commit 8878348
Show file tree
Hide file tree
Showing 11 changed files with 1,997 additions and 62 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ CLERK_SECRET_KEY="sk_test_..."
CONVEX_DEPLOYMENT="dev:..."

NEXT_PUBLIC_CONVEX_URL="https://..."

# Enviroment variables that Sentry will automatically set up for you
SENTRY_AUTH_TOKEN="sntrys_..."
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ yarn-error.log*
# PWA
public/sw.js
.env.local

# Sentry Config File
.env.sentry-build-plugin
7 changes: 6 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ export default [
},
},
{
files: ["convex/**", "src/env.ts"],
files: [
"convex/**",
"src/env.ts",
"next.config.js",
"src/instrumentation.ts",
],
rules: {
"no-restricted-properties": "off",
"no-restricted-imports": "off",
Expand Down
43 changes: 42 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fileURLToPath } from "node:url";
import { withSentryConfig } from "@sentry/nextjs";
import withSerwistInit from "@serwist/next";
import createJiti from "jiti";

Expand All @@ -16,7 +17,7 @@ const jiti = createJiti(fileURLToPath(import.meta.url));
jiti("./src/env.ts");

/** @type {import("next").NextConfig} */
const config = withSerwist({
const baseConfig = withSerwist({
transpilePackages: ["geist"],
experimental: {
reactCompiler: true,
Expand All @@ -32,4 +33,44 @@ const config = withSerwist({
},
});

const config = withSentryConfig(baseConfig, {
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options

org: "jakob-rossner",
project: "chat-io",

// 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",

// Hides source maps from generated client bundles
hideSourceMaps: true,

// 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,
});

export default config;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@radix-ui/react-select": "^2.1.2",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.4",
"@sentry/nextjs": "^8",
"@serwist/next": "9.0.10",
"@t3-oss/env-nextjs": "^0.11.1",
"babel-plugin-react-compiler": "19.0.0-beta-6fc168f-20241025",
Expand Down
1,905 changes: 1,845 additions & 60 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions sentry.client.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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: "https://630e38785fb6e187f60644670ed84a6b@o4508368710205440.ingest.de.sentry.io/4508368711712848",

// Add optional integrations for additional features
integrations: [Sentry.replayIntegration()],

// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,

// Define how likely Replay events are sampled.
// This sets the sample rate to be 10%. You may want this to be 100% while
// in development and sample at a lower rate in production
replaysSessionSampleRate: 0.1,

// Define how likely Replay events are sampled when an error occurs.
replaysOnErrorSampleRate: 1.0,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
});
16 changes: 16 additions & 0 deletions sentry.edge.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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: "https://630e38785fb6e187f60644670ed84a6b@o4508368710205440.ingest.de.sentry.io/4508368711712848",

// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
});
15 changes: 15 additions & 0 deletions sentry.server.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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: "https://630e38785fb6e187f60644670ed84a6b@o4508368710205440.ingest.de.sentry.io/4508368711712848",

// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
});
27 changes: 27 additions & 0 deletions src/app/global-error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"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 src/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;

0 comments on commit 8878348

Please sign in to comment.