Skip to content

Commit 3e52d41

Browse files
authored
fix: await Sentry. flush() on Vercel (#2)
1 parent 6b88176 commit 3e52d41

File tree

10 files changed

+284
-228
lines changed

10 files changed

+284
-228
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save-exact=true

next.config.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* This file sets a custom webpack configuration to use your Next.js app
33
* with Sentry.
4-
*
4+
*
55
* @see https://nextjs.org/docs/api-reference/next.config.js/introduction
66
* @see https://docs.sentry.io/platforms/javascript/guides/nextjs/
77
* @see https://blog.sentry.io/2020/08/04/enable-suspect-commits-unminify-js-and-track-releases-with-vercel-and-sentry
@@ -12,10 +12,9 @@ const withPlugins = require('next-compose-plugins')
1212
const withGraphql = require('next-plugin-graphql')
1313

1414
const moduleExports = {
15-
future: { webpack5: true },
1615
publicRuntimeConfig: {
17-
dns: process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN
18-
}
16+
dns: process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN,
17+
},
1918
}
2019

2120
const SentryWebpackPluginOptions = {

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
"private": true,
66
"scripts": {
77
"dev": "next",
8+
"format": "prettier pages -w",
89
"build": "next build",
910
"start": "next start"
1011
},
1112
"dependencies": {
12-
"@sentry/nextjs": "^6.8.0",
13-
"next": "^10.2.3",
14-
"react": "^17.0.2",
15-
"react-dom": "^17.0.2"
13+
"@sentry/nextjs": "6.13.2",
14+
"next": "11.1.2",
15+
"react": "17.0.2",
16+
"react-dom": "17.0.2"
1617
},
1718
"devDependencies": {
18-
"next-compose-plugins": "^2.2.1",
19-
"next-plugin-graphql": "^0.0.2"
19+
"next-compose-plugins": "2.2.1",
20+
"next-plugin-graphql": "0.0.2",
21+
"prettier": "2.4.1"
2022
}
2123
}

pages/_app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ MyApp.getInitialProps = async (appContext) => {
1111
return { ...appProps }
1212
}
1313

14-
export default MyApp
14+
export default MyApp

pages/_error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ MyError.getInitialProps = async ({ res, err, asPath }) => {
5151
// information about what the error might be. This is unexpected and may
5252
// indicate a bug introduced in Next.js, so record it in Sentry
5353
Sentry.captureException(
54-
new Error(`_error.js getInitialProps missing data at path: ${asPath}`)
54+
new Error(`_error.js getInitialProps missing data at path: ${asPath}`),
5555
)
5656
await Sentry.flush(2000)
5757

pages/api/test4.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ async function handler(req, res) {
1010
// Flushing before returning is necessary if deploying to Vercel, see
1111
// https://vercel.com/docs/platform/limits#streaming-responses
1212
await Sentry.flush(2000)
13+
1314
res.status(200).json({ name: 'John Doe' })
1415
}
1516

pages/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ import Image from 'next/image'
44
const Index = () => (
55
<div style={{ maxWidth: 700, margin: '0 auto' }}>
66
<h2>Sentry Simple Example 🚨</h2>
7-
<Image src="/pexels-polina-zimmerman-3747139.jpg" width="200" height="200"/>
8-
<p><a href="https://www.pexels.com/photo/black-smartphone-displaying-error-3747139/" target="_blank" rel="noopener noreferrer">Image Source</a></p>
7+
<Image
8+
src="/pexels-polina-zimmerman-3747139.jpg"
9+
width="200"
10+
height="200"
11+
/>
12+
<p>
13+
<a
14+
href="https://www.pexels.com/photo/black-smartphone-displaying-error-3747139/"
15+
target="_blank"
16+
rel="noopener noreferrer"
17+
>
18+
Image Source
19+
</a>
20+
</p>
921
<p>
1022
This example demonstrates how to record unhandled exceptions in your code
1123
with Sentry. There are several test pages below that result in various

pages/ssr/test4.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ export async function getServerSideProps() {
77
throw new Error('SSR Test 4')
88
} catch (error) {
99
Sentry.captureException(error)
10-
11-
// Flushing before returning is necessary if deploying to Vercel, see
12-
// https://vercel.com/docs/platform/limits#streaming-responses
13-
await Sentry.flush(2000)
1410
}
1511

12+
// Flushing before returning is necessary if deploying to Vercel, see
13+
// https://vercel.com/docs/platform/limits#streaming-responses
14+
await Sentry.flush(2000)
15+
1616
return { props: {} }
1717
}
1818

prettier.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
arrowParens: 'always',
3+
bracketSpacing: true,
4+
endOfLine: 'auto',
5+
printWidth: 80,
6+
proseWrap: 'always',
7+
semi: false,
8+
singleQuote: true,
9+
trailingComma: 'all',
10+
tabWidth: 2,
11+
useTabs: false,
12+
}

0 commit comments

Comments
 (0)