From 9ff71a9790fbe95335c67c44ac2cd74fc4ecd671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Mon, 26 Apr 2021 12:01:57 +0200 Subject: [PATCH 1/2] fix: Prevent InboundFilters mergeOptions method from breaking users code --- packages/browser/rollup.config.js | 6 ++++++ packages/core/src/integrations/inboundfilters.ts | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/browser/rollup.config.js b/packages/browser/rollup.config.js index e7edf544134c..20fa3f70ded1 100644 --- a/packages/browser/rollup.config.js +++ b/packages/browser/rollup.config.js @@ -17,6 +17,12 @@ const terserInstance = terser({ reserved: ['captureException', 'captureMessage', 'sentryWrapped'], properties: { regex: /^_[^_]/, + // This exclusion prevents most of the occurences of the bug linked below: + // https://github.com/getsentry/sentry-javascript/issues/2622 + // The bug is caused by multiple SDK instances, where one is minified and one is using non-mangled code. + // Unfortunatelly we cannot fix it reliably (thus `typeof` check in the `InboundFilters` code), + // as we cannot force people using multiple instances in their apps to sync SDK versions. + reserved: ['_mergeOptions'], }, }, }); diff --git a/packages/core/src/integrations/inboundfilters.ts b/packages/core/src/integrations/inboundfilters.ts index 106cc10caa0f..4803d89f5e57 100644 --- a/packages/core/src/integrations/inboundfilters.ts +++ b/packages/core/src/integrations/inboundfilters.ts @@ -46,10 +46,16 @@ export class InboundFilters implements Integration { if (self) { const client = hub.getClient(); const clientOptions = client ? client.getOptions() : {}; - const options = self._mergeOptions(clientOptions); - if (self._shouldDropEvent(event, options)) { - return null; + // This checks prevents most of the occurences of the bug linked below: + // https://github.com/getsentry/sentry-javascript/issues/2622 + // The bug is caused by multiple SDK instances, where one is minified and one is using non-mangled code. + // Unfortunatelly we cannot fix it reliably (thus reserved property in rollups terser config), + // as we cannot force people using multiple instances in their apps to sync SDK versions. + const options = typeof self._mergeOptions === 'function' ? self._mergeOptions(clientOptions) : {}; + if (typeof self._shouldDropEvent !== 'function') { + return event; } + return self._shouldDropEvent(event, options) ? null : event; } return event; }); From 64c758f7cb3f1ffd4de80621c74a346f909be7b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Mon, 26 Apr 2021 13:38:54 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Rodolfo Carvalho --- packages/browser/rollup.config.js | 2 +- packages/core/src/integrations/inboundfilters.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/browser/rollup.config.js b/packages/browser/rollup.config.js index 20fa3f70ded1..426dc49c233f 100644 --- a/packages/browser/rollup.config.js +++ b/packages/browser/rollup.config.js @@ -17,7 +17,7 @@ const terserInstance = terser({ reserved: ['captureException', 'captureMessage', 'sentryWrapped'], properties: { regex: /^_[^_]/, - // This exclusion prevents most of the occurences of the bug linked below: + // This exclusion prevents most of the occurrences of the bug linked below: // https://github.com/getsentry/sentry-javascript/issues/2622 // The bug is caused by multiple SDK instances, where one is minified and one is using non-mangled code. // Unfortunatelly we cannot fix it reliably (thus `typeof` check in the `InboundFilters` code), diff --git a/packages/core/src/integrations/inboundfilters.ts b/packages/core/src/integrations/inboundfilters.ts index 4803d89f5e57..61dfad5f47fd 100644 --- a/packages/core/src/integrations/inboundfilters.ts +++ b/packages/core/src/integrations/inboundfilters.ts @@ -46,10 +46,10 @@ export class InboundFilters implements Integration { if (self) { const client = hub.getClient(); const clientOptions = client ? client.getOptions() : {}; - // This checks prevents most of the occurences of the bug linked below: + // This checks prevents most of the occurrences of the bug linked below: // https://github.com/getsentry/sentry-javascript/issues/2622 // The bug is caused by multiple SDK instances, where one is minified and one is using non-mangled code. - // Unfortunatelly we cannot fix it reliably (thus reserved property in rollups terser config), + // Unfortunatelly we cannot fix it reliably (thus reserved property in rollup's terser config), // as we cannot force people using multiple instances in their apps to sync SDK versions. const options = typeof self._mergeOptions === 'function' ? self._mergeOptions(clientOptions) : {}; if (typeof self._shouldDropEvent !== 'function') {