From 447de7c08db2e867bf8e5269e582ed7a06968c0c Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Tue, 2 Nov 2021 11:08:30 +0100 Subject: [PATCH 1/3] feat(gatsby): Upload source maps automatically when sentry-cli is configured --- packages/gatsby/gatsby-node.js | 21 +++++++++++++++++++++ packages/gatsby/package.json | 3 ++- yarn.lock | 19 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/gatsby/gatsby-node.js b/packages/gatsby/gatsby-node.js index 721196b1f943..26291bb9cfd0 100644 --- a/packages/gatsby/gatsby-node.js +++ b/packages/gatsby/gatsby-node.js @@ -1,4 +1,5 @@ const fs = require('fs'); +const SentryWebpackPlugin = require('@sentry/webpack-plugin'); const sentryRelease = JSON.stringify( // Always read first as Sentry takes this as precedence @@ -29,6 +30,26 @@ exports.onCreateWebpackConfig = ({ plugins, getConfig, actions }) => { ], }); + if (process.env.NODE_ENV === 'production') { + actions.setWebpackConfig({ + plugins: [ + new SentryWebpackPlugin({ + include: 'public', + ignore: ['app-*', 'polyfill-*', 'framework-*', 'webpack-runtime-*'], + // 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 0a2699f71e60..6b22f726e4bf 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -27,7 +27,8 @@ }, "dependencies": { "@sentry/react": "6.13.3", - "@sentry/tracing": "6.13.3" + "@sentry/tracing": "6.13.3", + "@sentry/webpack-plugin": "1.18.3" }, "peerDependencies": { "gatsby": "^2.0.0 || ^3.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" From 1eb745519f366636076a7393c49b88b827109fe1 Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Tue, 2 Nov 2021 11:41:42 +0100 Subject: [PATCH 2/3] fix linting --- packages/gatsby/gatsby-node.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/gatsby/gatsby-node.js b/packages/gatsby/gatsby-node.js index 26291bb9cfd0..4bd5202a0c20 100644 --- a/packages/gatsby/gatsby-node.js +++ b/packages/gatsby/gatsby-node.js @@ -1,4 +1,5 @@ const fs = require('fs'); + const SentryWebpackPlugin = require('@sentry/webpack-plugin'); const sentryRelease = JSON.stringify( From 9c5ab34980bd3e0b212a71a48f816b6483bc8ffb Mon Sep 17 00:00:00 2001 From: iker barriocanal <32816711+iker-barriocanal@users.noreply.github.com> Date: Wed, 3 Nov 2021 15:41:03 +0100 Subject: [PATCH 3/3] Add comments of included and ignored files --- packages/gatsby/gatsby-node.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/gatsby/gatsby-node.js b/packages/gatsby/gatsby-node.js index 4bd5202a0c20..6b6e89ba8d27 100644 --- a/packages/gatsby/gatsby-node.js +++ b/packages/gatsby/gatsby-node.js @@ -35,8 +35,15 @@ exports.onCreateWebpackConfig = ({ plugins, getConfig, actions }) => { actions.setWebpackConfig({ plugins: [ new SentryWebpackPlugin({ + // Only include files from the build output directory include: 'public', - ignore: ['app-*', 'polyfill-*', 'framework-*', 'webpack-runtime-*'], + // 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) {