Skip to content

Commit

Permalink
fix(sentry): correctly setups the sentry integration
Browse files Browse the repository at this point in the history
fixes #92
  • Loading branch information
anguspiv committed Feb 21, 2023
1 parent 1fbb045 commit fe5ea8b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ build-storybook.log
.sentryclirc

types/nexus-typegen

# Sentry
.sentryclirc
14 changes: 13 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
module.exports = {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { withSentryConfig } = require('@sentry/nextjs');

const moduleExports = {
reactStrictMode: true,
sentry: {
hideSourceMaps: false,
},
};

const sentryWebpackPluginOptions = {
silent: true,
};

module.exports = withSentryConfig(moduleExports, sentryWebpackPluginOptions);
26 changes: 0 additions & 26 deletions next.config.wizardcopy.js

This file was deleted.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@hookform/resolvers": "^2.9.11",
"@next-auth/prisma-adapter": "^1.0.5",
"@prisma/client": "^4.10.1",
"@sentry/nextjs": "^7.37.2",
"@sentry/nextjs": "^7.38.0",
"@types/bytes": "^3.1.1",
"@types/graphql-upload": "^15.0.2",
"apollo-server-micro": "^3.11.1",
Expand Down
18 changes: 10 additions & 8 deletions pages/_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ const MyError = ({ statusCode, hasGetInitialPropsRun, err }) => {
return <NextErrorComponent statusCode={statusCode} />;
};

MyError.getInitialProps = async ({ res, err, asPath }) => {
const errorInitialProps = await NextErrorComponent.getInitialProps({
res,
err,
});
MyError.getInitialProps = async (context) => {
const errorInitialProps = await NextErrorComponent.getInitialProps(context);

const { res, err, asPath } = context;

// Workaround for https://github.com/vercel/next.js/issues/8592, mark when
// getInitialProps has run
errorInitialProps.hasGetInitialPropsRun = true;

// Returning early because we don't want to log 404 errors to Sentry.
if (res?.statusCode === 404) {
return errorInitialProps;
}

// Running on the server, the response object (`res`) is available.
//
// Next.js will pass an err on the server if a page's data fetching methods
Expand All @@ -50,9 +54,7 @@ MyError.getInitialProps = async ({ res, err, asPath }) => {
// If this point is reached, getInitialProps was called without any
// information about what the error might be. This is unexpected and may
// indicate a bug introduced in Next.js, so record it in Sentry
Sentry.captureException(
new Error(`_error.js getInitialProps missing data at path: ${asPath}`),
);
Sentry.captureException(new Error(`_error.js getInitialProps missing data at path: ${asPath}`));
await Sentry.flush(2000);

return errorInitialProps;
Expand Down
1 change: 1 addition & 0 deletions sentry.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Sentry.init({
dsn: SENTRY_DSN || 'https://4e506b139137430fa20d43cd2d526912@o1080632.ingest.sentry.io/6086695',
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,
environment: process.env.NEXT_PUBLIC_ENVIRONMENT || 'development',
// ...
// Note: if you want to override the automatic release value, do not set a
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
Expand Down
1 change: 1 addition & 0 deletions sentry.server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Sentry.init({
dsn: SENTRY_DSN || 'https://4e506b139137430fa20d43cd2d526912@o1080632.ingest.sentry.io/6086695',
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,
environment: process.env.NEXT_PUBLIC_ENVIRONMENT || 'development',
// ...
// Note: if you want to override the automatic release value, do not set a
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
Expand Down

0 comments on commit fe5ea8b

Please sign in to comment.