From fe674c2ffb746ef5fd155427cc990ade1be585b6 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 13 Feb 2024 11:49:10 +0100 Subject: [PATCH] feat(core): Lookup client on current scope, not hub One more step to avoid the hub... --- packages/core/src/exports.ts | 3 +-- packages/core/src/scope.ts | 4 ++-- packages/core/test/lib/tracing/trace.test.ts | 9 +++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/core/src/exports.ts b/packages/core/src/exports.ts index 56d64e2a64e9..cd27925c3726 100644 --- a/packages/core/src/exports.ts +++ b/packages/core/src/exports.ts @@ -349,8 +349,7 @@ export async function close(timeout?: number): Promise { * Get the currently active client. */ export function getClient(): C | undefined { - // eslint-disable-next-line deprecation/deprecation - return getCurrentHub().getClient(); + return getCurrentScope().getClient(); } /** diff --git a/packages/core/src/scope.ts b/packages/core/src/scope.ts index 43e200ede516..3356fd4d20d5 100644 --- a/packages/core/src/scope.ts +++ b/packages/core/src/scope.ts @@ -163,8 +163,8 @@ export class Scope implements ScopeInterface { * * It is generally recommended to use the global function `Sentry.getClient()` instead, unless you know what you are doing. */ - public getClient(): Client | undefined { - return this._client; + public getClient(): C | undefined { + return this._client as C | undefined; } /** diff --git a/packages/core/test/lib/tracing/trace.test.ts b/packages/core/test/lib/tracing/trace.test.ts index bb5302bb54db..a5c559950c9c 100644 --- a/packages/core/test/lib/tracing/trace.test.ts +++ b/packages/core/test/lib/tracing/trace.test.ts @@ -9,7 +9,6 @@ import { spanToJSON, withScope, } from '../../../src'; -import { Scope } from '../../../src/scope'; import { Span, continueTrace, @@ -304,7 +303,7 @@ describe('startSpan', () => { it('allows to pass a scope', () => { const initialScope = getCurrentScope(); - const manualScope = new Scope(); + const manualScope = initialScope.clone(); const parentSpan = new Span({ spanId: 'parent-span-id' }); // eslint-disable-next-line deprecation/deprecation manualScope.setSpan(parentSpan); @@ -463,7 +462,7 @@ describe('startSpanManual', () => { it('allows to pass a scope', () => { const initialScope = getCurrentScope(); - const manualScope = new Scope(); + const manualScope = initialScope.clone(); const parentSpan = new Span({ spanId: 'parent-span-id' }); // eslint-disable-next-line deprecation/deprecation manualScope.setSpan(parentSpan); @@ -568,7 +567,9 @@ describe('startInactiveSpan', () => { }); it('allows to pass a scope', () => { - const manualScope = new Scope(); + const initialScope = getCurrentScope(); + + const manualScope = initialScope.clone(); const parentSpan = new Span({ spanId: 'parent-span-id' }); // eslint-disable-next-line deprecation/deprecation manualScope.setSpan(parentSpan);