Skip to content

Commit 6b278f1

Browse files
feat(gatsby): Upload source maps automatically when sentry-cli is configured (#4109)
When `sentry-cli` is configured, source maps are automatically uploaded without requiring additional configuration from the user. When it's not, they aren't uploaded (doesn't break builds). The user can also define a custom configuration (in `gatsby-node.js`), which is higher priority than the one the SDK defines.
1 parent b99ee25 commit 6b278f1

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

packages/gatsby/gatsby-node.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const fs = require('fs');
22

3+
const SentryWebpackPlugin = require('@sentry/webpack-plugin');
4+
35
const sentryRelease = JSON.stringify(
46
// Always read first as Sentry takes this as precedence
57
process.env.SENTRY_RELEASE ||
@@ -29,6 +31,33 @@ exports.onCreateWebpackConfig = ({ plugins, getConfig, actions }) => {
2931
],
3032
});
3133

34+
if (process.env.NODE_ENV === 'production') {
35+
actions.setWebpackConfig({
36+
plugins: [
37+
new SentryWebpackPlugin({
38+
// Only include files from the build output directory
39+
include: 'public',
40+
// Ignore files that aren't users' source code related
41+
ignore: [
42+
'app-*', // related to Gatsby itself
43+
'polyfill-*', // related to polyfills
44+
'framework-*', // related to the frameworks (e.g. React)
45+
'webpack-runtime-*', // related to Webpack
46+
],
47+
// Handle sentry-cli configuration errors when the user has not done it not to break
48+
// the build.
49+
errorHandler(err, invokeErr) {
50+
const { message } = err;
51+
if (message.includes('organization slug is required') || message.includes('project slug is required')) {
52+
return;
53+
}
54+
invokeErr(err);
55+
},
56+
}),
57+
],
58+
});
59+
}
60+
3261
// To configure the SDK, SENTRY_USER_CONFIG is prioritized over `gatsby-config.js`,
3362
// since it isn't possible to set non-serializable parameters in the latter.
3463
// Prioritization here means what `init` is run.

packages/gatsby/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
},
2828
"dependencies": {
2929
"@sentry/react": "6.14.1",
30-
"@sentry/tracing": "6.14.1"
30+
"@sentry/tracing": "6.14.1",
31+
"@sentry/webpack-plugin": "1.18.3"
3132
},
3233
"peerDependencies": {
3334
"gatsby": "^2.0.0 || ^3.0.0 || ^4.0.0"

yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,13 +2832,32 @@
28322832
progress "^2.0.3"
28332833
proxy-from-env "^1.1.0"
28342834

2835+
"@sentry/cli@^1.70.1":
2836+
version "1.70.1"
2837+
resolved "https://registry.yarnpkg.com/@sentry/cli/-/cli-1.70.1.tgz#908517b699c0714eff88bedb68c6ea72e94945e8"
2838+
integrity sha512-pab3nU3rNsq1HKKmJP2ITDl5cGi+QbQ5eLX6ELaeAbN2eAzfndHu2rTqlnjJAKcYQg6l9gFBn8vvY2xAeRJb6Q==
2839+
dependencies:
2840+
https-proxy-agent "^5.0.0"
2841+
mkdirp "^0.5.5"
2842+
node-fetch "^2.6.0"
2843+
npmlog "^4.1.2"
2844+
progress "^2.0.3"
2845+
proxy-from-env "^1.1.0"
2846+
28352847
28362848
version "1.18.1"
28372849
resolved "https://registry.yarnpkg.com/@sentry/webpack-plugin/-/webpack-plugin-1.18.1.tgz#0fa24297043305057111d85a7154d4b8b24d43a6"
28382850
integrity sha512-maEnHC0nxRnVgAz0qvKvhTGy+SxneR8MFjpgNMvh9CyAB6GEM9VQI1hzxTcAd7Qk90qGW8W4eUmB+ZX8nMrM1w==
28392851
dependencies:
28402852
"@sentry/cli" "^1.68.0"
28412853

2854+
2855+
version "1.18.3"
2856+
resolved "https://registry.yarnpkg.com/@sentry/webpack-plugin/-/webpack-plugin-1.18.3.tgz#1cd3401f84f561b4a451dac5f42465ee5102f5d6"
2857+
integrity sha512-Qk3Jevislc5DZK0X/WwRVcOtO7iatnWARsEgTV/TuXvDN+fUDDpD/2MytAWAbpLaLy3xEB/cXGeLsbv6d1XNkQ==
2858+
dependencies:
2859+
"@sentry/cli" "^1.70.1"
2860+
28422861
"@simple-dom/interface@^1.4.0":
28432862
version "1.4.0"
28442863
resolved "https://registry.yarnpkg.com/@simple-dom/interface/-/interface-1.4.0.tgz#e8feea579232017f89b0138e2726facda6fbb71f"

0 commit comments

Comments
 (0)