Uh oh!
There was an error while loading. Please reload this page.
feat(gatsby): Support non-serializable SDK options - #4064
Conversation
size-limit report
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| @@ -1,17 +1,63 @@ | |||
| const Sentry = require('@sentry/gatsby'); | |||
| // To avoid confusion, you must set the Sentry configuration in one | |||
There was a problem hiding this comment.
I think this behaviour is still too complicated. Let's just make it so that if sentry.config.{js, ts} is defined, that will always take priority over the plugin params (and then we can just log a warning if plugin params are also used).
There was a problem hiding this comment.
We can then also rm -rf all this enabled logic.
There was a problem hiding this comment.
Simplified the logic. We can't get rid of the isSentryInitialized because the gatsby-browser script's scope is in the browser, so we need to still check for the Sentry instance. But, we are no longer playing around with the enabled.
If... - The SDK has been initialized in a config file, use that instance. If options are also defined, log a warning to merge the options. - The SDK has not been initialized, initialize it. Unless options have not been provided, and log an error if that happens.
rhcarvalho
left a comment
There was a problem hiding this comment.
Was curious to see how this is implemented. A few suggestions / stale comments (?).
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Adds the docs supporting the Gatsby SDK initialization in a config file, see getsentry/sentry-javascript#4064.
…API (#20048) closes#20043 closes [JS-2024](https://linear.app/getsentry/issue/JS-2024/sentrygatsby-build-can-fail-with-typeerror-invokeerr-is-not-a-function) The `@sentry/bundler-plugin-core` was updated to call `errorHandler` with only a single `Error` argument, but the Gatsby plugin's `errorHandler` still expected two arguments `(err, invokeErr)`. This caused builds to fail with "TypeError: invokeErr is not a function" when a Sentry error occurred during source map upload. It was originally added in #4064, where we still had v1 of the `@senrty/webpack-plugin` (where the type still existed: https://github.com/getsentry/sentry-webpack-plugin/blob/cb854281eb409c5c14f6a0d1042429240644a48d/index.d.ts#L112). With v2, and the move to [our new repo](https://github.com/getsentry/sentry-javascript-bundler-plugins), this option got removed and is no longer part of it. So `invokeErr` is safe to remove, and should have been already with this PR #11292 Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
The current Gatsby SDK requires to set the SDK options in
gatsby-config.js, which doesn't allow to set non-serializable options. This PR introducessentry.config.js, a file where you can define yourSentry.initwith non-serializable options. The current approach of defining the SDK options is still supported. Only one of the two approaches can be used; if a user defines both, theinitinsentry.config.jsis prioritized and other options are ignored.This PR is a follow-up to #4040.
How does this work?
That file is injected into the webpack config's entry properties, which makes the SDK to initialize before
gatsby-browser.jsis run, the only place where the SDK was being initialized before. That script has the following behavior:sentry.config.jsand there are options defined ingatsby-config.js, a warning message telling the user to merge both configs is logged. The SDK is initialized with theinitin the config file.sentry.config.jsand there aren't any options defined ingatsby-config.js, an error message telling the user init options aren't defined is logged, linking to the docs.