Skip to content

Commit

Permalink
fix: support configuring "CaptureConsole" and "Debug" integrations (#275
Browse files Browse the repository at this point in the history
)

Resolves #274
  • Loading branch information
rchl authored Feb 17, 2021
1 parent 3dadc25 commit 73c5b12
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions docs/content/en/sentry/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ Normally, just setting DSN would be enough.
}
```
- Sentry by default also enables these browser integrations: `InboundFilters`, `FunctionToString`, `TryCatch`, `Breadcrumbs`, `GlobalHandlers`, `LinkedErrors`, `UserAgent`. Their options can be overridden by specifying them manually in the object.
- Here is the list of client integrations that are supported: `Breadcrumbs`, `CaptureConsole`, `Debug`, `Dedupe`, `ExtraErrorData`, `FunctionToString`, `GlobalHandlers`, `InboundFilters`, `LinkedErrors`, `ReportingObserver`, `RewriteFrames`, `TryCatch`, `UserAgent`, `Vue`.
- See https://docs.sentry.io/platforms/javascript/configuration/integrations/default/ and https://docs.sentry.io/platforms/javascript/configuration/integrations/plugin/ for more information on configuring integrations


### serverIntegrations
- Type: `Dictionary`
- Default:
Expand All @@ -202,6 +204,7 @@ Normally, just setting DSN would be enough.
Transaction: {}
}
```
- Here is a list of server integrations that are supported: `CaptureConsole`, `Debug`, `Dedupe`, `ExtraErrorData`, `RewriteFrames`, `Modules`, `Transaction`.
- See https://docs.sentry.io/platforms/node/pluggable-integrations/ for more information

### tracing
Expand Down
16 changes: 12 additions & 4 deletions lib/core/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import WebpackPlugin from '@sentry/webpack-plugin'
import { canInitialize, clientSentryEnabled, serverSentryEnabled } from './utils'

const SERVER_CONFIG_FILENAME = 'sentry.server.config.js'
const SENTRY_DEFAULT_INTEGRATIONS = ['Dedupe', 'ExtraErrorData', 'ReportingObserver', 'RewriteFrames', 'Vue']
const SENTRY_PLUGGABLE_INTEGRATIONS = ['CaptureConsole', 'Debug', 'Dedupe', 'ExtraErrorData', 'ReportingObserver', 'RewriteFrames', 'Vue']
const SENTRY_BROWSER_INTEGRATIONS = ['InboundFilters', 'FunctionToString', 'TryCatch', 'Breadcrumbs', 'GlobalHandlers', 'LinkedErrors', 'UserAgent']
const SENTRY_SERVER_INTEGRATIONS = ['CaptureConsole', 'Debug', 'Dedupe', 'ExtraErrorData', 'RewriteFrames', 'Modules', 'Transaction']

/** @param {import('../../types/sentry').IntegrationsConfiguration} integrations */
const filterDisabledIntegration = integrations => Object.keys(integrations).filter(key => integrations[key])
Expand Down Expand Up @@ -103,20 +104,27 @@ export async function buildHook (moduleContainer, options, logger) {
}

for (const name of Object.keys(options.clientIntegrations)) {
if (!SENTRY_DEFAULT_INTEGRATIONS.includes(name) && !SENTRY_BROWSER_INTEGRATIONS.includes(name)) {
logger.warn(`Sentry integration "${name}" is not recognized and will be ignored.`)
if (!SENTRY_PLUGGABLE_INTEGRATIONS.includes(name) && !SENTRY_BROWSER_INTEGRATIONS.includes(name)) {
logger.warn(`Sentry clientIntegration "${name}" is not recognized and will be ignored.`)
delete options.clientIntegrations[name]
}
}

for (const name of Object.keys(options.serverIntegrations)) {
if (!SENTRY_SERVER_INTEGRATIONS.includes(name)) {
logger.warn(`Sentry serverIntegration "${name}" is not recognized and will be ignored.`)
delete options.serverIntegrations[name]
}
}

// Register the client plugin
const pluginOptionClient = clientSentryEnabled(options) ? (options.lazy ? 'lazy' : 'client') : 'mocked'
moduleContainer.addPlugin({
src: resolve(__dirname, '..', `plugin.${pluginOptionClient}.js`),
fileName: 'sentry.client.js',
mode: 'client',
options: {
SENTRY_DEFAULT_INTEGRATIONS,
SENTRY_PLUGGABLE_INTEGRATIONS,
SENTRY_BROWSER_INTEGRATIONS,
dev: moduleContainer.options.dev,
runtimeConfigKey: options.runtimeConfigKey,
Expand Down
2 changes: 1 addition & 1 deletion lib/plugin.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import merge from 'lodash.merge'
import * as Sentry from '@sentry/browser'
<%
if (options.initialize) {
let integrations = options.SENTRY_DEFAULT_INTEGRATIONS.filter(key => key in options.integrations)
let integrations = options.SENTRY_PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations)
if (integrations.length) {%>import { <%= integrations.join(', ') %> } from '@sentry/integrations'
<%}
integrations = options.SENTRY_BROWSER_INTEGRATIONS.filter(key => key in options.integrations)
Expand Down
2 changes: 1 addition & 1 deletion lib/plugin.lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async function loadSentry (ctx, inject) {
const Sentry = await import(/* <%= magicComments.join(', ') %> */ '@sentry/browser')
<%
if (options.initialize) {
let integrations = options.SENTRY_DEFAULT_INTEGRATIONS.filter(key => key in options.integrations)
let integrations = options.SENTRY_PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations)
if (integrations.length) {%>const { <%= integrations.join(', ') %> } = await import(/* <%= magicComments.join(', ') %> */ '@sentry/integrations')
<% }
integrations = options.SENTRY_BROWSER_INTEGRATIONS.filter(key => key in options.integrations)
Expand Down

0 comments on commit 73c5b12

Please sign in to comment.