Skip to content

Commit 7933761

Browse files
authored
fix: update list of allowed integrations and allow configuring them (#513)
1 parent 4518ab8 commit 7933761

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

docs/content/en/sentry/options.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ Note that the module sets the following defaults when publishing is enabled:
236236
RewriteFrames: {},
237237
}
238238
```
239-
- Sentry by default also enables the following browser integrations: `InboundFilters`, `FunctionToString`, `TryCatch`, `Breadcrumbs`, `GlobalHandlers`, `LinkedErrors`, `Dedupe`, `HttpContext`.
239+
- Sentry by default also enables the following browser integrations: `Breadcrumbs`, `Dedupe`, `FunctionToString`, `GlobalHandlers`, `HttpContext`, `InboundFilters`, `LinkedErrors`, `TryCatch`.
240+
- When `tracing` option is enabled then the [Vue Router Instrumentation](https://docs.sentry.io/platforms/javascript/guides/vue/configuration/integrations/vue-router/) is also enabled.
240241
- The full list of client integrations that are supported: `Breadcrumbs`, `CaptureConsole`, `Debug`, `Dedupe`, `ExtraErrorData`, `FunctionToString`, `GlobalHandlers`, `HttpClient`, `HttpContext`, `InboundFilters`, `LinkedErrors`, `ReportingObserver`, `RewriteFrames`, `TryCatch`.
241242
- Integration options can be specified in the object value corresponding to the individual integration key.
242243
- To disable integration that is enabled by default, pass `false` as a value. For example to disable `ExtraErrorData` integration (only), set the option to:
@@ -258,9 +259,10 @@ Note that the module sets the following defaults when publishing is enabled:
258259
Dedupe: {},
259260
ExtraErrorData: {},
260261
RewriteFrames: {},
262+
Transaction: {},
261263
}
262264
```
263-
- Sentry by default also enables the following server integrations: `InboundFilters`, `FunctionToString`, `Console`, `Http`, `OnUncaughtException`, `OnUnhandledRejection`, `ContextLines`, `Context`, `Modules`, `RequestData`, `LinkedErrors`.
265+
- Sentry by default enables the following server integrations: `Console`, `ContextLines`, `Context`, `FunctionToString`, `Http`, `InboundFilters`, `LinkedErrors`, `Modules`,`OnUncaughtException`, `OnUnhandledRejection`, `RequestData`.
264266
- The full list of server integrations that are supported includes the ones above plus: `CaptureConsole`, `Debug`, `Dedupe`, `ExtraErrorData`, `RewriteFrames`, `Transaction`.
265267
- Integration options can be specified in the object value corresponding to the individual integration key.
266268
- To disable integration that is enabled by default, pass `false` as a value. For example to disable `ExtraErrorData` integration (only), set the option to:
@@ -269,6 +271,7 @@ Note that the module sets the following defaults when publishing is enabled:
269271
Dedupe: {},
270272
ExtraErrorData: false,
271273
RewriteFrames: {},
274+
Transaction: {},
272275
}
273276
```
274277
- See also [Sentry Server Integrations](https://docs.sentry.io/platforms/node/configuration/integrations/) for more information on configuring each integration.

lib/core/options.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import merge from 'lodash.mergewith'
22
// @ts-ignore
33
import { relativeTo } from '@nuxt/utils'
4-
import * as Integrations from '@sentry/integrations'
4+
import { Integrations as ServerIntegrations } from '@sentry/node'
5+
import * as ServerPluggableIntegrations from '@sentry/integrations'
56
import { canInitialize } from './utils'
67

7-
export const PLUGGABLE_INTEGRATIONS = ['CaptureConsole', 'Debug', 'Dedupe', 'ExtraErrorData', 'HttpClient', 'ReportingObserver', 'RewriteFrames']
8-
export const BROWSER_INTEGRATIONS = ['InboundFilters', 'FunctionToString', 'TryCatch', 'Breadcrumbs', 'GlobalHandlers', 'LinkedErrors', 'HttpContext']
9-
const SERVER_INTEGRATIONS = ['CaptureConsole', 'Debug', 'Dedupe', 'ExtraErrorData', 'RewriteFrames', 'Modules', 'Transaction']
8+
// Enabled by default in Vue - https://docs.sentry.io/platforms/javascript/guides/vue/configuration/integrations/default/
9+
export const BROWSER_INTEGRATIONS = ['Breadcrumbs', 'Dedupe', 'FunctionToString', 'GlobalHandlers', 'HttpContext', 'InboundFilters', 'LinkedErrors', 'TryCatch']
10+
// Optional in Vue - https://docs.sentry.io/platforms/javascript/guides/vue/configuration/integrations/plugin/
11+
export const BROWSER_PLUGGABLE_INTEGRATIONS = ['CaptureConsole', 'Debug', 'ExtraErrorData', 'HttpClient', 'ReportingObserver', 'RewriteFrames']
12+
// Enabled by default in Node.js - https://docs.sentry.io/platforms/node/configuration/integrations/default-integrations/
13+
const SERVER_INTEGRATIONS = ['Console', 'ContextLines', 'FunctionToString', 'Http', 'InboundFilters', 'LinkedErrors', 'LocalVariables', 'Modules', 'OnUncaughtException', 'OnUnhandledRejection', 'RequestData']
14+
// Optional in Node.js - https://docs.sentry.io/platforms/node/configuration/integrations/pluggable-integrations/
15+
const SERVER_PLUGGABLE_INTEGRATIONS = ['CaptureConsole', 'Debug', 'Dedupe', 'ExtraErrorData', 'RewriteFrames', 'Transaction']
1016

1117
/** @param {import('../../types/sentry').IntegrationsConfiguration} integrations */
1218
const filterDisabledIntegrations = integrations => Object.keys(integrations).filter(key => integrations[key])
@@ -136,7 +142,7 @@ export async function resolveClientOptions (moduleContainer, moduleOptions, logg
136142
resolveTracingOptions(options, options.config)
137143

138144
for (const name of Object.keys(options.clientIntegrations)) {
139-
if (!PLUGGABLE_INTEGRATIONS.includes(name) && !BROWSER_INTEGRATIONS.includes(name)) {
145+
if (![...BROWSER_INTEGRATIONS, ...BROWSER_PLUGGABLE_INTEGRATIONS].includes(name)) {
140146
logger.warn(`Sentry clientIntegration "${name}" is not recognized and will be ignored.`)
141147
delete options.clientIntegrations[name]
142148
}
@@ -153,8 +159,8 @@ export async function resolveClientOptions (moduleContainer, moduleOptions, logg
153159
}
154160

155161
return {
156-
PLUGGABLE_INTEGRATIONS,
157162
BROWSER_INTEGRATIONS,
163+
BROWSER_PLUGGABLE_INTEGRATIONS,
158164
dev: moduleContainer.options.dev,
159165
runtimeConfigKey: options.runtimeConfigKey,
160166
config: {
@@ -188,7 +194,7 @@ export async function resolveServerOptions (moduleContainer, moduleOptions, logg
188194
const options = merge({}, moduleOptions)
189195

190196
for (const name of Object.keys(options.serverIntegrations)) {
191-
if (!SERVER_INTEGRATIONS.includes(name)) {
197+
if (![...SERVER_INTEGRATIONS, ...SERVER_PLUGGABLE_INTEGRATIONS].includes(name)) {
192198
logger.warn(`Sentry serverIntegration "${name}" is not recognized and will be ignored.`)
193199
delete options.serverIntegrations[name]
194200
}
@@ -209,12 +215,21 @@ export async function resolveServerOptions (moduleContainer, moduleOptions, logg
209215

210216
const defaultConfig = {
211217
dsn: options.dsn,
212-
intergrations: [
218+
integrations: [
213219
...filterDisabledIntegrations(options.serverIntegrations)
214220
.map((name) => {
215221
const opt = options.serverIntegrations[name]
216-
// @ts-ignore
217-
return Object.keys(opt).length ? new Integrations[name](opt) : new Integrations[name]()
222+
try {
223+
if (SERVER_INTEGRATIONS.includes(name)) {
224+
// @ts-ignore
225+
return Object.keys(opt).length ? new ServerIntegrations[name](opt) : new ServerIntegrations[name]()
226+
} else {
227+
// @ts-ignore
228+
return Object.keys(opt).length ? new ServerPluggableIntegrations[name](opt) : new ServerPluggableIntegrations[name]()
229+
}
230+
} catch (error) {
231+
throw new Error(`Failed initializing server integration "${name}".\n${error}`)
232+
}
218233
}),
219234
...customIntegrations,
220235
],

lib/plugin.client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as Sentry from '~@sentry/vue'
55
<% if (options.tracing) { %>import { BrowserTracing } from '~@sentry/tracing'<% } %>
66
<%
77
if (options.initialize) {
8-
let integrations = options.PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations)
8+
let integrations = options.BROWSER_PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations)
99
if (integrations.length) {%>import { <%= integrations.join(', ') %> } from '~@sentry/integrations'
1010
<%}
1111
if (options.clientConfigPath) {%>import getClientConfig from '<%= options.clientConfigPath %>'

lib/plugin.lazy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ async function loadSentry (ctx, inject) {
113113
<% if (options.tracing) { %>const { BrowserTracing } = await import(/* <%= magicComments.join(', ') %> */ '~@sentry/tracing')<% } %>
114114
<%
115115
if (options.initialize) {
116-
let integrations = options.PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations)
116+
let integrations = options.BROWSER_PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations)
117117
if (integrations.length) {%>const { <%= integrations.join(', ') %> } = await import(/* <%= magicComments.join(', ') %> */ '~@sentry/integrations')
118118
<% }
119119
integrations = options.BROWSER_INTEGRATIONS.filter(key => key in options.integrations)

0 commit comments

Comments
 (0)