From 07c6838307a2dc265b4caf59fb5a97065b63db25 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Thu, 16 May 2024 11:29:21 +0200 Subject: [PATCH] fix(core): Avoid looking up client for `hasTracingEnabled()` if possible (#12066) This is a bit weird in that we access the current scope & client etc., even if options are passed. Since we also use this method in `init()` before we have setup stuff, it seems safer to avoid calling this at all if possible. This is related to https://github.com/getsentry/sentry-javascript/issues/12054, but not really the cause of it. --- packages/core/src/utils/hasTracingEnabled.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/core/src/utils/hasTracingEnabled.ts b/packages/core/src/utils/hasTracingEnabled.ts index a4a854edf314..97463d9d5e5e 100644 --- a/packages/core/src/utils/hasTracingEnabled.ts +++ b/packages/core/src/utils/hasTracingEnabled.ts @@ -16,7 +16,11 @@ export function hasTracingEnabled( return false; } - const client = getClient(); - const options = maybeOptions || (client && client.getOptions()); + const options = maybeOptions || getClientOptions(); return !!options && (options.enableTracing || 'tracesSampleRate' in options || 'tracesSampler' in options); } + +function getClientOptions(): Options | undefined { + const client = getClient(); + return client && client.getOptions(); +}