Skip to content

Commit

Permalink
Merge pull request #748 from kduprey/feature/add-sentry-issue-tracking
Browse files Browse the repository at this point in the history
feat: Add @sentry/nextjs dependency for error tracking and monitoring
  • Loading branch information
kduprey authored Jul 1, 2024
2 parents 2abbf8a + f11692c commit 232b5c8
Show file tree
Hide file tree
Showing 8 changed files with 1,521 additions and 23 deletions.
40 changes: 40 additions & 0 deletions apps/frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,45 @@ module.exports = {
},
experimental: {
optimizePackageImports: ["@kduprey/config"],
instrumentationHook: true,
},
};

// Injected content via Sentry wizard below

const { withSentryConfig } = require("@sentry/nextjs");

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

org: "kenton-duprey",
project: "kentonduprey-site",

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

// 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: false,

// 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,
});
1 change: 1 addition & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@sanity/preview-url-secret": "^1.6.17",
"@sanity/react-loader": "^1.10.3",
"@sanity/webhook": "^4.0.4",
"@sentry/nextjs": "^8",
"axios": "^1.7.2",
"jsonwebtoken": "^9.0.2",
"next": "^14.2.4",
Expand Down
36 changes: 36 additions & 0 deletions apps/frontend/sentry.client.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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({
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,

dsn: "https://[email protected]/4506956612632576",

// You can remove this option if you're not planning to use the Sentry Session Replay feature:
integrations: [
Sentry.replayIntegration({
blockAllMedia: false,
// Additional Replay configuration goes in here, for example:
maskAllText: false,
networkCaptureBodies: true,
networkDetailAllowUrls: [
// Allow all network requests
/.*/,
],
}),
Sentry.browserTracingIntegration(),
],

replaysOnErrorSampleRate: 1.0,

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

// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,
});
16 changes: 16 additions & 0 deletions apps/frontend/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://[email protected]/4507523620864000",

// 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,
});
19 changes: 19 additions & 0 deletions apps/frontend/sentry.server.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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://[email protected]/4507523620864000",

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

// Uncomment the line below to enable Spotlight (https://spotlightjs.com)
// spotlight: process.env.NODE_ENV === 'development',

});
25 changes: 25 additions & 0 deletions apps/frontend/src/app/global-error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use client";

import * as Sentry from "@sentry/nextjs";
import NextError from "next/error";
import { useEffect } from "react";

const GlobalError = ({ error }: { error: Error & { digest?: string } }) => {
useEffect(() => {
Sentry.captureException(error);
}, [error]);

return (
<html lang="en">
<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>
);
};

export default GlobalError;
9 changes: 9 additions & 0 deletions apps/frontend/src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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');
}
}
Loading

0 comments on commit 232b5c8

Please sign in to comment.