Skip to content

Commit

Permalink
feat(src): 🥅 Add sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
Nudelsuppe42 committed Aug 21, 2024
1 parent b7da3cb commit 6408aad
Show file tree
Hide file tree
Showing 9 changed files with 1,383 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ yarn-error.log*

package-lock.json

public/locales/en/translations.zip
public/locales/en/translations.zip
# Sentry Config File
.env.sentry-build-plugin
44 changes: 44 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,47 @@ const nextConfig = {
};

module.exports = withBundleAnalyzer(nextConfig);


// 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: "buildtheearth",
project: "main-website",
sentryUrl: "https://sentry.buildtheearth.net/",

// 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: 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: false,
}
);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@next/bundle-analyzer": "^13.5.6",
"@react-three/drei": "^9.56.10",
"@react-three/fiber": "^8.10.1",
"@sentry/nextjs": "8",
"@tabler/icons-react": "^2.35.0",
"@tiptap/extension-highlight": "^2.0.2",
"@tiptap/extension-link": "^2.0.2",
Expand Down Expand Up @@ -110,4 +111,4 @@
"typescript": "^4.7.2",
"webpack-bundle-analyzer": "^4.5.0"
}
}
}
18 changes: 18 additions & 0 deletions sentry.client.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as Sentry from '@sentry/nextjs';

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
tracesSampleRate: 1,
debug: false,
replaysOnErrorSampleRate: 1.0,
replaysSessionSampleRate: 0.05,
maxBreadcrumbs: 10,
integrations: [
Sentry.replayIntegration({
// Additional Replay configuration goes in here, for example:
maskAllText: true,
blockAllMedia: true,
}),
],
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
});
9 changes: 9 additions & 0 deletions sentry.edge.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/nextjs';

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
maxBreadcrumbs: 5,
tracesSampleRate: 1,
debug: false,
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
});
9 changes: 9 additions & 0 deletions sentry.server.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/nextjs';

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
tracesSampleRate: 1,
maxBreadcrumbs: 5,
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
debug: false,
});
9 changes: 9 additions & 0 deletions 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');
}
}
26 changes: 16 additions & 10 deletions src/pages/_error.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Sentry from '@sentry/nextjs';

import {
Button,
Center,
Expand All @@ -7,12 +9,13 @@ import {
useMantineTheme,
} from '@mantine/core';

import Error from 'next/error';
import Image from 'next/image';
import type { NextPageContext } from 'next';
import Page from '@/components/Page';
import thumbnail from '@/public/images/thumbnails/error.png';
import { useTranslation } from 'next-i18next';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import Image from 'next/image';
import { useRouter } from 'next/router';
import { useTranslation } from 'next-i18next';

function ErrorPage(props: any) {
const theme = useMantineTheme();
Expand Down Expand Up @@ -90,13 +93,16 @@ function ErrorPage(props: any) {
</Page>
);
}
export async function getStaticProps({ locale }: any) {
return {
props: {
...(await serverSideTranslations(locale, ['common'])),
},
};
}

ErrorPage.getInitialProps = async (contextData: NextPageContext) => {
await Sentry.captureUnderscoreErrorException(contextData);

return Error.getInitialProps({
...contextData,
// ...(await serverSideTranslations(contextData.locale || 'en', ['common'])),
});
};

export default ErrorPage;

const errors: any = {
Expand Down
Loading

0 comments on commit 6408aad

Please sign in to comment.