From 26380bedd96443939b59d8fcdd4f5216f8fca21a Mon Sep 17 00:00:00 2001 From: Kazuhito Hokamura Date: Sat, 25 Jul 2020 22:50:44 +0900 Subject: [PATCH] Update Sentry example to improve display of server errors --- examples/with-sentry/next.config.js | 3 +++ examples/with-sentry/package.json | 1 + examples/with-sentry/pages/_app.js | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/examples/with-sentry/next.config.js b/examples/with-sentry/next.config.js index 7b8cb6549d6e6..21f6635917c7f 100644 --- a/examples/with-sentry/next.config.js +++ b/examples/with-sentry/next.config.js @@ -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 diff --git a/examples/with-sentry/package.json b/examples/with-sentry/package.json index 2247484221ae0..7d1ba55478e5e 100644 --- a/examples/with-sentry/package.json +++ b/examples/with-sentry/package.json @@ -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", diff --git a/examples/with-sentry/pages/_app.js b/examples/with-sentry/pages/_app.js index 4a3037ce39baa..6dd8e80766169 100644 --- a/examples/with-sentry/pages/_app.js +++ b/examples/with-sentry/pages/_app.js @@ -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, }) }