From 50f1a90e52df305448110fc6309f2c5a5e8f9cda Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 23 Mar 2023 18:59:21 +0000 Subject: [PATCH 1/6] Throw error when extension methods are missing --- packages/core/src/hub.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/core/src/hub.ts b/packages/core/src/hub.ts index f67ae3773325..f915083de47b 100644 --- a/packages/core/src/hub.ts +++ b/packages/core/src/hub.ts @@ -480,7 +480,15 @@ export class Hub implements HubInterface { if (sentry && sentry.extensions && typeof sentry.extensions[method] === 'function') { return sentry.extensions[method].apply(this, args); } - __DEBUG_BUILD__ && logger.warn(`Extension method ${method} couldn't be found, doing nothing.`); + throw new Error(`Extension method '${method}' couldn't be found. Tracing extensions have not been added. +Call 'addTracingExtensions' before calling 'init': + +Sentry.addTracingExtensions(); + +Sentry.init({ + ... +}); +`); } } From 8366d910e2358181877271b130e26cd4e6ae091d Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 23 Mar 2023 19:07:15 +0000 Subject: [PATCH 2/6] shorter --- packages/core/src/hub.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/hub.ts b/packages/core/src/hub.ts index f915083de47b..94ca3497cd0a 100644 --- a/packages/core/src/hub.ts +++ b/packages/core/src/hub.ts @@ -480,7 +480,7 @@ export class Hub implements HubInterface { if (sentry && sentry.extensions && typeof sentry.extensions[method] === 'function') { return sentry.extensions[method].apply(this, args); } - throw new Error(`Extension method '${method}' couldn't be found. Tracing extensions have not been added. + throw new Error(`Tracing extension '${method}' has not been added. Call 'addTracingExtensions' before calling 'init': Sentry.addTracingExtensions(); From e635e55e9cf3f798de1c31d41dc2f0ce90ef3af2 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 23 Mar 2023 19:12:01 +0000 Subject: [PATCH 3/6] shorter still --- packages/core/src/hub.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/core/src/hub.ts b/packages/core/src/hub.ts index 94ca3497cd0a..992af62c3c5e 100644 --- a/packages/core/src/hub.ts +++ b/packages/core/src/hub.ts @@ -480,14 +480,10 @@ export class Hub implements HubInterface { if (sentry && sentry.extensions && typeof sentry.extensions[method] === 'function') { return sentry.extensions[method].apply(this, args); } - throw new Error(`Tracing extension '${method}' has not been added. -Call 'addTracingExtensions' before calling 'init': + throw new Error(`Tracing extension '${method}' has not been added. Call 'addTracingExtensions' before calling 'init': Sentry.addTracingExtensions(); - -Sentry.init({ - ... -}); +Sentry.init({...}); `); } } From e1a0eb1c6bbdf83c3c9e6480689af10568d74077 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Mon, 27 Mar 2023 11:10:03 +0100 Subject: [PATCH 4/6] Only throw in debug mode and startTransaction --- packages/core/src/hub.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/core/src/hub.ts b/packages/core/src/hub.ts index 992af62c3c5e..3f3f486ee433 100644 --- a/packages/core/src/hub.ts +++ b/packages/core/src/hub.ts @@ -361,7 +361,17 @@ export class Hub implements HubInterface { * @inheritDoc */ public startTransaction(context: TransactionContext, customSamplingContext?: CustomSamplingContext): Transaction { - return this._callExtensionMethod('startTransaction', context, customSamplingContext); + const result = this._callExtensionMethod('startTransaction', context, customSamplingContext); + + if (__DEBUG_BUILD__ && !result) { + throw new Error(`Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init': + +Sentry.addTracingExtensions(); +Sentry.init({...}); +`); + } + + return result; } /** @@ -480,10 +490,14 @@ export class Hub implements HubInterface { if (sentry && sentry.extensions && typeof sentry.extensions[method] === 'function') { return sentry.extensions[method].apply(this, args); } - throw new Error(`Tracing extension '${method}' has not been added. Call 'addTracingExtensions' before calling 'init': + throw new Error(`Tracing extension '${method}' has not been added. +Call 'addTracingExtensions' before calling 'init': Sentry.addTracingExtensions(); -Sentry.init({...}); + +Sentry.init({ + ... +}); `); } } From 0710db936e7dd8a2663bcb901e3f89af6e2d1269 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Mon, 27 Mar 2023 14:50:47 +0100 Subject: [PATCH 5/6] revert change --- packages/core/src/hub.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/core/src/hub.ts b/packages/core/src/hub.ts index 3f3f486ee433..adb3b0e726d7 100644 --- a/packages/core/src/hub.ts +++ b/packages/core/src/hub.ts @@ -490,15 +490,7 @@ Sentry.init({...}); if (sentry && sentry.extensions && typeof sentry.extensions[method] === 'function') { return sentry.extensions[method].apply(this, args); } - throw new Error(`Tracing extension '${method}' has not been added. -Call 'addTracingExtensions' before calling 'init': - -Sentry.addTracingExtensions(); - -Sentry.init({ - ... -}); -`); + __DEBUG_BUILD__ && logger.warn(`Extension method ${method} couldn't be found, doing nothing.`); } } From 716836c7871b037b7b27189710530bf04021ecf7 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Sun, 9 Apr 2023 21:31:34 +0200 Subject: [PATCH 6/6] console.warn rather than throw --- packages/core/src/hub.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/hub.ts b/packages/core/src/hub.ts index adb3b0e726d7..57363aaea6c1 100644 --- a/packages/core/src/hub.ts +++ b/packages/core/src/hub.ts @@ -364,8 +364,8 @@ export class Hub implements HubInterface { const result = this._callExtensionMethod('startTransaction', context, customSamplingContext); if (__DEBUG_BUILD__ && !result) { - throw new Error(`Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init': - + // eslint-disable-next-line no-console + console.warn(`Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init': Sentry.addTracingExtensions(); Sentry.init({...}); `);