Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Sentry example to improve display of server errors #15495

Merged
merged 3 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/with-sentry/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const COMMIT_SHA =
process.env.SENTRY_DSN = SENTRY_DSN

module.exports = withSourceMaps({
serverRuntimeConfig: {
rootDir: __dirname,
},
webpack: (config, options) => {
// In `pages/_app.js`, Sentry is imported from @sentry/browser. While
// @sentry/node will run in a Node.js environment. @sentry/node will use
Expand Down
1 change: 1 addition & 0 deletions examples/with-sentry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"@sentry/browser": "^5.15.5",
"@sentry/integrations": "5.20.1",
"@sentry/node": "^5.15.5",
"@sentry/webpack-plugin": "^1.11.1",
"@zeit/next-source-maps": "0.0.4-canary.1",
Expand Down
12 changes: 12 additions & 0 deletions examples/with-sentry/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import * as Sentry from '@sentry/node'
import { RewriteFrames } from '@sentry/integrations'
import getConfig from 'next/config'

if (process.env.NEXT_PUBLIC_SENTRY_DSN) {
const config = getConfig()
const distDir = `${config.serverRuntimeConfig.rootDir}/.next`
Sentry.init({
enabled: process.env.NODE_ENV === 'production',
integrations: [
new RewriteFrames({
iteratee: (frame) => {
frame.filename = frame.filename.replace(distDir, 'app:///_next')
return frame
},
}),
],
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
})
}
Expand Down