Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(gatsby): Support non-serializable SDK options#4064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iker-barriocanal
merged 11 commits into
master
from
iker/fix/gatsby-non-serializable-optsOct 22, 2021
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9acb791
fix(gatsby): Support non-serializable SDK options
iker-barriocanal cf31a72
Add comments and TODOs
iker-barriocanal 01573c5
fix browser tests
iker-barriocanal 00363ef
Merge branch 'master' into iker/fix/gatsby-non-serializable-opts
iker-barriocanal 41c41db
Support TS config files
iker-barriocanal 0e60931
simplify browser logic
iker-barriocanal 6685552
Clarify outdated comment
iker-barriocanal 4d63460
catch potential erros on `existsSync`
iker-barriocanal 4ce50e0
Use `forEach` instead of `map`
iker-barriocanal b3c4a82
Merge branch 'master' into iker/fix/gatsby-non-serializable-opts
iker-barriocanal 91e5787
Merge branch 'master' into iker/fix/gatsby-non-serializable-opts
iker-barriocanal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,27 @@ | ||
| /* eslint-disable no-console */ | ||
| const Sentry = require('@sentry/gatsby'); | ||
| exports.onClientEntry = function(_, pluginParams) { | ||
| if (pluginParams === undefined) { | ||
| const isIntialized = isSentryInitialized(); | ||
| const areOptionsDefined = areSentryOptionsDefined(pluginParams); | ||
| if (isIntialized) { | ||
| window.Sentry = Sentry; // For backwards compatibility | ||
| if (areOptionsDefined) { | ||
| console.warn( | ||
| 'Sentry Logger [Warn]: The SDK was initialized in the Sentry config file, but options were found in the Gatsby config. ' + | ||
| 'These have been ignored, merge them to the Sentry config if you want to use them.\n' + | ||
| 'Learn more about the Gatsby SDK on https://docs.sentry.io/platforms/javascript/guides/gatsby/', | ||
iker-barriocanal marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ); | ||
| } | ||
| return; | ||
| } | ||
| if (!areOptionsDefined) { | ||
| console.error( | ||
| 'Sentry Logger [Error]: No config for the Gatsby SDK was found.\n' + | ||
rhcarvalho marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| 'Learn how to configure it on https://docs.sentry.io/platforms/javascript/guides/gatsby/', | ||
| ); | ||
| return; | ||
| } | ||
| @@ -12,6 +32,21 @@ exports.onClientEntry = function(_, pluginParams) { | ||
| dsn: __SENTRY_DSN__, | ||
| ...pluginParams, | ||
| }); | ||
| window.Sentry = Sentry; | ||
| window.Sentry = Sentry; // For backwards compatibility | ||
| }; | ||
| function isSentryInitialized() { | ||
| // Although `window` should exist because we're in the browser (where this script | ||
| // is run), and `__SENTRY__.hub` is created when importing the Gatsby SDK, double | ||
| // check that in case something weird happens. | ||
| return !!(window && window.__SENTRY__ && window.__SENTRY__.hub && window.__SENTRY__.hub.getClient()); | ||
| } | ||
| function areSentryOptionsDefined(params) { | ||
| if (params == undefined) return false; | ||
| // Even if there aren't any options, there's a `plugins` property defined as an empty array | ||
| if (Object.keys(params).length == 1 && Array.isArray(params.plugins) && params.plugins.length == 0) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.