diff --git a/packages/gatsby/gatsby-node.js b/packages/gatsby/gatsby-node.js index 721196b1f943..6b6e89ba8d27 100644 --- a/packages/gatsby/gatsby-node.js +++ b/packages/gatsby/gatsby-node.js @@ -1,5 +1,7 @@ const fs = require('fs'); +const SentryWebpackPlugin = require('@sentry/webpack-plugin'); + const sentryRelease = JSON.stringify( // Always read first as Sentry takes this as precedence process.env.SENTRY_RELEASE || @@ -29,6 +31,33 @@ exports.onCreateWebpackConfig = ({ plugins, getConfig, actions }) => { ], }); + if (process.env.NODE_ENV === 'production') { + actions.setWebpackConfig({ + plugins: [ + new SentryWebpackPlugin({ + // Only include files from the build output directory + include: 'public', + // Ignore files that aren't users' source code related + ignore: [ + 'app-*', // related to Gatsby itself + 'polyfill-*', // related to polyfills + 'framework-*', // related to the frameworks (e.g. React) + 'webpack-runtime-*', // related to Webpack + ], + // Handle sentry-cli configuration errors when the user has not done it not to break + // the build. + errorHandler(err, invokeErr) { + const { message } = err; + if (message.includes('organization slug is required') || message.includes('project slug is required')) { + return; + } + invokeErr(err); + }, + }), + ], + }); + } + // To configure the SDK, SENTRY_USER_CONFIG is prioritized over `gatsby-config.js`, // since it isn't possible to set non-serializable parameters in the latter. // Prioritization here means what `init` is run. diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index a8bf9bf44414..794dfbaa2fe2 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -27,7 +27,8 @@ }, "dependencies": { "@sentry/react": "6.14.1", - "@sentry/tracing": "6.14.1" + "@sentry/tracing": "6.14.1", + "@sentry/webpack-plugin": "1.18.3" }, "peerDependencies": { "gatsby": "^2.0.0 || ^3.0.0 || ^4.0.0" diff --git a/yarn.lock b/yarn.lock index d8eecd8e553f..eee4cdb3c545 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2832,6 +2832,18 @@ progress "^2.0.3" proxy-from-env "^1.1.0" +"@sentry/cli@^1.70.1": + version "1.70.1" + resolved "https://registry.yarnpkg.com/@sentry/cli/-/cli-1.70.1.tgz#908517b699c0714eff88bedb68c6ea72e94945e8" + integrity sha512-pab3nU3rNsq1HKKmJP2ITDl5cGi+QbQ5eLX6ELaeAbN2eAzfndHu2rTqlnjJAKcYQg6l9gFBn8vvY2xAeRJb6Q== + dependencies: + https-proxy-agent "^5.0.0" + mkdirp "^0.5.5" + node-fetch "^2.6.0" + npmlog "^4.1.2" + progress "^2.0.3" + proxy-from-env "^1.1.0" + "@sentry/webpack-plugin@1.18.1": version "1.18.1" resolved "https://registry.yarnpkg.com/@sentry/webpack-plugin/-/webpack-plugin-1.18.1.tgz#0fa24297043305057111d85a7154d4b8b24d43a6" @@ -2839,6 +2851,13 @@ dependencies: "@sentry/cli" "^1.68.0" +"@sentry/webpack-plugin@1.18.3": + version "1.18.3" + resolved "https://registry.yarnpkg.com/@sentry/webpack-plugin/-/webpack-plugin-1.18.3.tgz#1cd3401f84f561b4a451dac5f42465ee5102f5d6" + integrity sha512-Qk3Jevislc5DZK0X/WwRVcOtO7iatnWARsEgTV/TuXvDN+fUDDpD/2MytAWAbpLaLy3xEB/cXGeLsbv6d1XNkQ== + dependencies: + "@sentry/cli" "^1.70.1" + "@simple-dom/interface@^1.4.0": version "1.4.0" resolved "https://registry.yarnpkg.com/@simple-dom/interface/-/interface-1.4.0.tgz#e8feea579232017f89b0138e2726facda6fbb71f"