From 2059dfdb223009b1b25d3718774dc7db81302fdd Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Thu, 16 May 2024 11:09:40 +0200 Subject: [PATCH] fix(core): Avoid looking up client for `hasTracingEnabled()` if possible 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. --- 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(); +}